In this Page, We are Providing Python Programming – Pre-Defined Attributes. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.
Python Programming – Pre-Defined Attributes
Pre-defined attributes
Class and class instance objects has some pre-defined attributes:
Class object
Some pre-defined attributes of class object are:
__name__
This attribute give the class name.
>>> MYClass . __name__ ' MYClass '
__module__
This attribute give the module name.in which the class was defined.
>>> MYClass . ___module___ ' ___main___ '
- Python Data Persistence – class Keyword
- Python Data Persistence – Constructor
- Python Data Persistence – property () Function
___dict___
A class has a namespace implemented by a dictionary object. Class attribute references are translated to lookups in this dictionary, e.g., MyClass . i is translated to MyClass .___dict___ [ ” i ” ].
>>> MyClass.___dict___ { ' i ' : 12345 , '___module___' : '___main___ ' , '___doc___ ': ' A simple example class ' , ' f ' : <function f at 0x0640A070>}
___bases___
This attribute give the tuple (possibly empty or a singleton) containing the base classes.
>>> MyClass.___bases___. ( )
___doc___
This attribute give the class documentation string, or None, if not defined.
>>> MyClass.___doc___ ' A simple example class '
Class instance object
Some pre-defined attributes of class instance object are:
___dict___
This give attribute dictionary of class instance.
>>> x. ___dict___ { }
___class___
This give the instance’s class.
>>> x. ___class____ <class ___main___ .MyClass at 0x063DA880>