What is the python built-in class attribute? How do I invoke Python built-in class properties?

Source: Internet
Author: User
Tags class definition
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>} 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.