In this article, let's look at the built-in class properties in Python, some of whom may have just come into contact with Python's programming language,
python built-in propertiesThe understanding of the relatively small, not clear about
python built-in classesAttribute this aspect of knowledge. In the next article, let's look at Python's built-in class properties.
Python built-in class properties
1.__DICT__: Properties of the Class (contains a dictionary, consisting of the data properties of the Class)
2.__DOC__: Document string for Class
3.__NAME__: Class name
4.__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)
5.__BASES__: All parent classes of a class make up elements that contain 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, Sala RY): self.name = name self.salary = Salary Employee.empcount + = 1 def displaycount (self): print " Total Employee%d '% employee.empcount def displayemployee (self): print "Name:", Self.name, ", Salary:", Self.s Alary print "employee.__doc__:", Employee.__doc__print "employee.__name__:", Employee.__name__print "Employee. __module__: ", Employee.__module__print" employee.__bases__: ", Employee.__bases__print" Employee.__dict__: ", employee.__dict__
Execute the above code to output the result as follows:
employee.__doc__: base class for all employees employee.__name__: employeeemployee.__module__: __ Main__employee.__bases__: () employee.__dict__: {' __module__ ': ' __main__ ', ' displaycount ': <function displayCount at 0x10a939c80>, ' Empcount ': 0, ' displayemployee ': <function displayemployee at 0x10a93caa0> ' __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>}