Python class Propertiesis a function of the language itself, this article will explain through the example of what is
Python class letters,and how to use
Python access properties.
A. The Python class properties are:
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
two. So how do you go about accessing properties with Python ?
We can use the dot number. To access the properties of the object. Access the class variable using the name of the following class:
Emp1.displayemployee () Emp2.displayemployee () print "Total Employee%d"% Employee.empcount
Contact one, two, let's give an example
#!/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.salary 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>}