हिंदी

Differentiate between class attributes and instance attributes.

Advertisements
Advertisements

प्रश्न

Differentiate between class attributes and instance attributes.

अंतर स्पष्ट करें
Advertisements

उत्तर

Basis of Difference Class Attributes Instance Attributes
Meaning Attributes that belong to the class. Attributes that belong to an individual object.
Declaration Defined directly inside the class body. Usually defined using self inside __init__ or another method.
Sharing Shared by all instances of the class. Separate copy/value for each instance.
Access Accessed using ClassName.attribute or object.attribute. Generally accessed using object.attribute.
Example school = "DPS" self.name = name
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 3: Classes in Python - EXERCISE [पृष्ठ ६२]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 3 Classes in Python
EXERCISE | Q 9. | पृष्ठ ६२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×