Python Basic Learning Log method for day6-class

Source: Internet
Author: User
Tags instance method

One: The method description of the class

The method of class is divided into instance method, destructor method, construction method, class method, static method, attribute method, etc.

Both class and static methods can be called by class and class instances, and class instance methods can only be called by class instances

The implied invocation parameter of a class method is a class, and the implied invocation parameter of a class instance method is an instance of the class, and the static method does not implicitly invoke the argument

1) Instance method: The method that an instance of the class can use.

2) destructor: A method defined in a class using the Def __init__ (self), that is, the function is executed when the class is instantiated. Then we can put the attributes that we want to initialize first into this function.

3) Construction Method: __del__ "is a destructor, when using Del Delete object, will call his own destructor, in addition, when the object is called in a scope, the destructor will be called once when it jumps out of its scope, which can be used to free memory space

4) static method: is a normal function that is in the namespace defined by the class and does not operate on any instance type.

Use the adorner @staticmethod to define a static method. Both class objects and instances can call static methods.

Only nominal collation management, in fact, in a static method can not access any of the properties in the instance of the class

5) class method: A class method is a method of manipulating the class itself as an object. Class methods are defined using the @classmethod adorner. class method: Only class variables can be accessed and instance variables cannot be accessed

Two: Sample code

  

Python Basic Learning Log method for day6-class

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.