Python-04182016-Understanding of attributes between classes and instances

Source: Internet
Author: User

Python is a very flexible language, and it can be seen in light of the access mechanism of the properties between its classes and instances, but this is really not a good idea, and after doing some tests, I understand that:

When the instance accesses the Class property, first retrieves its own names, if has the words to take out directly, does not have the words to come to the names inside to look for, cannot find is the error

classPclass (object):"""docstring for Pclass"""Num= 10def __init__(self): Super (Pclass, self).__init__() P=Pclass ()Print(P.num)#TenP.num = p.num + 1Print(P.num)# OnePrint(Pclass.num)#TenPclass.age=12Print(Pclass.age)# APrint(P.age)# Ap.xxx=555Print(P.XXX)#555Print(PCLASS.XXX)#Attributeerror:type object ' Pclass ' has no attribute ' xxx '

Python-04182016-Understanding of attributes between classes and instances

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.