"Python" property

Source: Internet
Author: User

In Python, everything is Object (object), and objects have many properties (Arrtribute)

2 Types of attributes

Class attribute (class attribute): Class itself defines or inherits

Object attribute: The object instance defines the

Reserved properties: (= Object properties??) )

>>> Class1.__doc__       #type help information ' Class1 Doc. '>>> Class1.__name__      #type name ' Class1 '>>> Class1.__module__    #type module ' __main__ '>>> Class1.__bases__     #The base class that the type inherits from (<type ' object ');>>> Class1.__dict__      #a type dictionary that stores all type member information. <dictproxy object at 0x00d3ad70>>>> Class1 ().__class__   #type <class ' __main__. Class1 ' >>>> Class1 ().__module__  #instance type module ' __main__ '>>> Class1 ().__dict__    #Object dictionary that stores all instance member information. {' I ': 1234}

The properties of the object??? (The sense that the tutorial was written incorrectly, should be a class attribute) is stored in the object's __dict__ property. __dict__ is a dictionary, the key is the property name, and the corresponding value is the property itself.

classBird:#Bird Parent classHave_feater=true#property ' Have_feater ': Trueway_of_reproduction="Egg"   #attribute ' way_of_reproduction ': ' Egg 'song="Twitter"             #attribute ' song ': ' Twitter '    defSing (self):#' Sing ': <function bird.sing at 0x0000000001f0bb70>        Print(Self.song)defMove (self):#' move ': <function bird.move at 0x0000000001f0bbf8>        Print(" Fei Fei Fei")#attribute ' __weakref__ ': <attribute ' __weakref__ ' of ' Bird ' Objects>#attribute ' __doc__ ': None,#attribute ' __dict__ ': <attribute ' __dict__ ' of ' Bird ' Objects>#property ' __module__ ': ' __main__classChicken (Bird):#Birds Sub-categorysong="oooooo"                   #attribute ' song ': ' Oooooo '    def __init__(self,name):#property ' __init__ ': <function chicken.__init__ at 0x0000000001f0bc80>Self.name=namedefMove (self):#property ' move ': <function chicken.move at 0x0000000001f0bd08>        Print(" Run, run, run.")#attribute ' __doc__ ': None,#attribute ' __module__ ': ' __main__ 'Mychicken=chicken ("QQ")#property ' name ': ' QQ '#If you have only the object name, you can get the class by __class__, and then __base__ get the parent classPrint(Mychicken.__class__.__base__)Print(Bird.__dict__)Print(Chicken.__dict__)Print(Mychicken.__dict__)

"Python" property

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.