python-Object-oriented

Source: Internet
Author: User

1. How to use the class
# First Define Class Luffystudent (): School = "Luffycity" # Data attribute def learn (self): # Function Property Print ("Is learning ...") def sleep (self): # Function Property Print ("Is sleeping ...") # View the namespace of the class print (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School ': ' luffycity ', ' learn ': <function Luffystudent.learn at 0x00000000025b8b70> ' Sleep ': <function Luffystudent.sleep at 0x00000000025b8bf8>, ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __ weakref__ ': <attribute ' __weakref__ ' of ' luffystudent ' objects>, ' __doc__ ': None}print (luffystudent.__dict__[) School "]) # Luffycityprint (luffystudent.__dict__[" Learn "]) # <function Luffystudent.learn at 0x00000000025b8b70 ># Check Print (luffystudent.school) # luffycityprint (luffystudent.learn) # <function Luffystudent.learn at 0x0000000002158ae8># luffystudent.country = "China" Print (luffystudent.country) # china# Delete del Luffystudent.countryprint (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School': ' luffycity ', ' learn ': <function Luffystudent.learn at 0x0000000002158ae8>, ' Sleep ': <function Luffystudent.sleep at 0x0000000002158b70>, ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __ weakref__ ': <attribute ' __weakref__ ' of ' luffystudent ' objects>, ' __doc__ ': none}# change luffystudent.school = "Foguang University "Print (luffystudent.__dict__) # {' __module__ ': ' __main__ ', ' School ': ' Foguang University ', ' Learn ': < function Luffystudent.learn at 0x0000000002158ae8>, ' Sleep ': <function luffystudent.sleep at 0x0000000002158b70 , ' __dict__ ': <attribute ' __dict__ ' of ' luffystudent ' objects>, ' __weakref__ ': <attribute ' __weakref__ ' of ' Luffystudent ' objects>, ' __doc__ ': None}

To be Continued ...

python-Object-oriented

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.