Self in Python (Python note)

Source: Internet
Author: User
Self

There is only one special difference between the methods of classes in Python and normal functions-they must have an extra first parameter name, but you do not assign a value to this parameter when calling this method, and Python provides this value. This particular variable refers to the object itself, according to the Convention its name is self . Although you can give this parameter any name, it is best to use self this name-other names are deprecated.

If there is a class called fruit and an instance of this class, Apple. When you call this instance of Apple .method(arg1, arg2) , this will be automatically converted from Python to fruit .method(apple, arg1, arg2) -that's how it self works. This also means that if you have a method that does not require parameters, you need to define a parameter for the method self .

Search

Copy

Self in Python (Python note)

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.