Python Learning--static methods, class methods, property methods

Source: Internet
Author: User

ImportOS#Os.system ()#Os.mkdir ()classDog (object):#name = ' KK '    def __init__(self,name): Self.name=name#@staticmethod #静态方法, it's really nothing to do with the class, and it's not going to take the self argument. #@classmethod #类方法, the self parameter can be called, but the instantiated variable cannot be called. @property#static properties, cannot pass in parameters, can only invoke the properties of the class or instance itself.     defEat (self):Print("%s is eating%s"% (Self.name,'DD'))    defTalk (self):Print("%s is talking"%self.name) d= Dog ("Chenronghua") D.eatd.talk ()

Class
Variable
class variables
Instance variable
Private variables
Method
constructor function
Destructors
Private methods

Object
Instantiate a class and then get an object

Packaging
Hide the implementation details of some features

Inherited
Re-use code
Single Inheritance (max)
Multiple inheritance
2.7 Classic class, depth first
The new class after 3.0 is breadth first

Polymorphic
One interface, multiple implementations


Static methods
Only nominally attributed to the class to manage, but in fact there is no way to access the static method of the class or any attribute inside the instance

Class method
Only class variables can be accessed and instance variables cannot be accessed


Property method
Turn a method into a static property. You can change and delete methods by using the method name. Setter and method name. deleter.

Python Learning--static methods, class methods, property methods

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.