The understanding of the self of Python

Source: Internet
Author: User

Where is the position of self?

First, self is in the method of the class, and when this method is called, it is not assigned a value, and Python automatically assigns it to it, and this value is the instance of the class-the object itself. You can also change self to other names such as Seef, but not recommended, because it is customary to write self as a default.

When writing code, the class's method system directly has self, as follows:

Second, self is the default first parameter of the class method and is required, without writing an error.

Second, what is the value of self?

The value of self is automatically assigned by Python, and the value is the object itself. For example: Class Dog, whose instance is D, then, when D calls the method Jian (arge1,arge2) of the class, Python automatically transitions to Dog.jian (d,arge1,arge2). The value of Self is instance D of dog.

The following example prints the value of self. (The intance in the printed result is the meaning of the instance)

The understanding of the self of Python

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.