Python built-in class properties
- __DICT__: Properties of the Class (contains a dictionary, consisting of the data properties of the Class)
- __DOC__: Document string for Class
- __NAME__: Class name
- __MODULE__: The module where the class definition resides (the full name of the class is ' __main__.classname ', if the class is in an import module mymod, then classname.__module__ equals Mymod)
- __BASES__: All parent classes of a class make up elements (containing a tuple of all the parent classes)
The python built-in class property invocation instance is as follows:
#!/usr/bin/python#-*-Coding:utf-8-*-Class Employee: ' base class for all employees 'Empcount= 0 Def__init__(Self,Name,Salary): Self.Name=NameSelf.Salary=SalaryEmployee.Empcount+= 1 DefDisplaycount(Self): Print "Total Employee%d" % Employee.EmpcountDefDisplayemployee(Self): Print "Name:", Self.Name, ", Salary:", Self.SalaryPrint "Employee.__doc__:", Employee.__doc__print employee. __name__print ,< Span class= "PLN" > employee.print ,< Span class= "PLN" > employee.print ,< Span class= "PLN" > employee.
Execute the above code to output the result as follows:
Employee.__doc__: Base class for all employeesEmployee.__name__: EmployeeEmployee.__module__:__main__Employee.__bases__: ()Employee.__dict__: {' __module__ ': ' __main__ ', ' Displaycount ': <functionDisplaycount at0x10a939c80, ' empcount ' : 0, ' displayemployee ' : <function Displayemployee at 0x10a93caa0< Span class= "pun" >>, ' __doc__ ' : ' \XE6\X89\X80\XE6\X9C\X89\XE5\X91\X98\XE5\XB7\XA5\XE7\X9A\X84\XE5\X9F\XBA\XE7\XB1\XBB ' , ' __init__ ' : <function __init__ at 0x10a939578 >}
Python-built-in class properties