python--built-in properties

Source: Internet
Author: User

I. Common built-in properties

help (class or instance) The class All parent classes of the The
Common proprietary Properties Description Trigger Mode
__init__ construct initialization function After creating an instance, when assigning values, after __new__
__new__ Build instance required properties Create instance
__class__ instance where the td> instance resides. __class__
__str__ Instance string representation, readability print (class instance), using REPR results if not implemented
__repr__ Instance string representation, accuracy class instance carriage return or print (Repr (class instance))
__del__ destructor del Delete instance
__dict__ instance from Define Property VARs (instance. __dict__)
__doc__ class document, subclass does not inherit
__getattribute__ Property Access interceptors Access instance Properties
__bases__ class constitute elements class name. __bases__

1. Use of property interceptors

classItcast (object):def __init__(Self,subject1): Self.subject1=Subject1 Self.subject2='CPP'    #property Access when the Interceptor, hit log    def __getattribute__(self,obj):ifobj = ='Subject1':            Print('Log Subject1')            return 'redirect Python'        Else:#comment out these 2 lines when testing, will not find Subject2            returnObject.__getattribute__(self,obj)defShow (self):Print('This is itcast') s= Itcast ("python")Print(S.subject1)Print(S.SUBJECT2)#ResultsLog Subject1redirect pythoncpp
use of property interceptors

python--built-in properties

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.