Tools, FAQ, Tutorials:
Manage and Use Instance Properties
How to manage and use instance properties?
✍: FYIcenter.com
Instance properties, also called instance attributes, are name value pairs
associated with class instance object,
and not shared with other instances created from this class.
You can manage and use instance properties in various places:
1. In the class "__init__()" method statement block - You can add new instance property and assign its initial value in the class "__init__()" method statement block. In this case, you need to use the instance name and the property name in the dot (.) expression format to identify the property: instance_name.property_name. For example:
>>> class user(): ... nextID = 1 ... def __init__(self,name="Joe",age=25): ... self.id = user.nextID ... self.name = name ... self.age = age ... ...
In the above example, "self.id", "self.name" and "self.age" represents 3 instance properties.
3. In any Python code after the instance is created - You can add new instance property, assign its initial value, access its value and change its value in any Python code after the instance is created. In this case, you need to use the instance name and the property name in the dot (.) expression format to identify the property: instance_name.property_name. For example:
>>> class user(): ... ... ... >>> x = user() >>> x.name 'Joe' >>> x.remark = "Smart guy!" >>> x.remark 'Smart guy!'
⇒ Where Are Instance Properties Stored
⇐ '__init__()' Class Method to Initialize New Instance
2022-09-24, 1127👍, 0💬
Popular Posts:
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...
How to use the XML to JSON Conversion Tool at freeformatter.com? If you want to try the XML to JSON ...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
How to use "xml-to-json" Azure API Policy Statement? The "xml-to-json" Policy Statement allows you t...