Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> Python

Python में delattr() फंक्शन क्या करता है?

Python delattr()

delattr() ऑब्जेक्ट से एट्रिब्यूट डिलीट करता है यदि ऑब्जेक्ट अनुमति देता है।

सिंटैक्स

delattr() का सिंटैक्स है:

delattr(object, name)

delattr() मेथड दो पैरामीटर्स लेता है:

delattr() कोई मान नहीं लौटाता (None लौटाता है)। यह केवल एट्रिब्यूट हटाता है (यदि ऑब्जेक्ट अनुमति देता है)।

उदाहरण

class Coordinate:
    x = 12
    y = -7
    z = 0

point1 = Coordinate()
print('x =', point1.x)
print('y =', point1.y)
print('z =', point1.z)

delattr(Coordinate, 'z')
print('--After deleting z attribute--')
print('x =', point1.x)
print('y =', point1.y)
# Raises Error
print('z =', point1.z)

आउटपुट

यह आउटपुट देता है:

x = 12
y = -7
z = 0
--After deleting z attribute--
x = 12
y = -7
AttributeError: Coordinate instance has no attribute 'z'
  1. - Python में reload() Function क्या करता है?

    reload() Function reload(moduleName) Function एक Previously Loaded Module को Reload करता है (यह मानते हुए कि आपने इसे import moduleName Syntax के साथ Load किया था)। यह Conversational Use के लिए Intended है, जहां आपने किसी Module के Source File को Edit किया है और Python को छोड़े बिना और इसे फिर से S

  1. - Python में Namespace क्या है?

    Python में Namespace Namespace Scope को Implement करने का एक तरीका है। Python में, प्रत्येक Package, Module, Class, Function और Method Function का अपना एक Namespace होता है जिसमें Variable Names Resolve होते हैं। जब कोई Function, Module या Package Evaluate होता है (यानी Execution शुरू होता है), तो

  1. - Python में Strings पर % Operator क्या करता है?

    % String Formatting Operator % एक String Formatting Operator या Interpolation Operator है। दिए गए format % values (जहां Format एक String है), Format में % Conversion Specifications को Values के Zero या अधिक Elements से Replace किया जाता है। Effect C Language में sprintf() का उपयोग करने के समान है।