Basic Python and python tutorials

Source: Internet
Author: User

Basic Python and python tutorials

Python is a flexible language. You can see this by looking at the access mechanism of its class and instance attributes, but this is really hard to understand, after some tests, I understand that:

When an instance accesses the class attribute, it first retrieves its own names. If so, it will retrieve them directly. If not, it will find the names in the class. If not, it will be an error.

 

Class Pclass (object): "docstring for Pclass" num = 10 def _ init _ (self): super (Pclass, self ). _ init _ () p = Pclass () print (p. num) # 10p. num = p. num + 1 print (p. num) #11 print (Pclass. num) # 10Pclass. age = 12 print (Pclass. age) #12 print (p. age) # 12p. XXXXX = 555 print (p. xxx) #555 print (Pclass. xxx) # AttributeError: type object 'pclass 'has no attribute 'xxx'

 

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.