Home  >  Article  >  Backend Development  >  What are python built-in class attributes? How to call python built-in class properties?

What are python built-in class attributes? How to call python built-in class properties?

乌拉乌拉~
乌拉乌拉~Original
2018-08-20 14:38:302666browse

In this article, let’s learn about the built-in class attributes in python. Some friends may have just come into contact with the programming language python and have less understanding of python’s built-in attributes. Not sure about the python built-in class attributes. In the next article, we will learn about Python's built-in class attributes.

python built-in class attributes

1.__dict__: attributes of the class (contains a dictionary composed of data attributes of the class)

2.__doc__ :Document string of the class

3.__name__: Class name

4.__module__: Module where the class is defined (the full name of the class is '__main__.className', if the class is located in an import In the module mymod, then className.__module__ is equal to mymod)

5.__bases__: All parent classes of the class constitute elements (contains a tuple composed of all parent classes)

Python built-in classes An example of attribute calling is as follows:

# !/usr/bin/python
# -*- coding: UTF-8 -*-
class Employee:
    '所有员工的基类'
    empCount = 0
    def __init__(self, name, salary):
        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__

The output result of executing the above code is as follows:

Employee.__doc__: 所有员工的基类
Employee.__name__: Employee
Employee.__module__: __main__
Employee.__bases__: ()
Employee.__dict__: {&#39;__module__&#39;: &#39;__main__&#39;, &#39;displayCount&#39;: <function displayCount at 0x10a939c80>, &#39;empCount&#39;: 0, &#39;displayEmployee&#39;: <function displayEmployee at 0x10a93caa0>, &#39;__doc__&#39;: &#39;\xe6\x89\x80\xe6\x9c\x89\xe5\x91\x98\xe5\xb7\xa5\xe7\x9a\x84\xe5\x9f\xba\xe7\xb1\xbb&#39;, &#39;__init__&#39;: <function __init__ at 0x10a939578>}

The above is all the content described in this article. This article mainly introduces python built-in class attributes knowledge. I hope you can use the information to understand what is said above and the examples given. I hope what I have described in this article will be helpful to you and make it easier for you to learn python.

For more related knowledge, please visit the Python tutorial column on the php Chinese website.

The above is the detailed content of What are python built-in class attributes? How to call python built-in class properties?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more