When defining a function in Python, how does self understand:

Source: Internet
Author: User

When defining a method, there is a self parameter, which is used in all method declarations, which represents the instance object itself, when you invoke the method with an instance, the interpreter automatically passes the instance object itself silently to the method, and does not need you to pass self in, For example, there is a method with two parameters, and all of your calls need only pass in two parameters.   For example these two files: file name:  test.py class a:    def  abc (self,a,b):        a=a+1        b=b+1 file name:  test2.py import aa.abc (Print a), btest2.py If you use a A, B, two parameters, you need to pass a A, a two parameter, in addition to these two parameters, but also need to pass, then the self is the other information represented;       Instance object: What is an instance object?       Instantiate objects you can generally understand the meaning of being quoted ...      For example, your father has a car ... Do you want to drive ...? This time, you have to tell your dad that the car lent me to open, and then your father's key to you, you can open it! If you don't say it, you'll never get away with a key.!      instantiation of the same meaning, you put a class as an object, as a car, you want to open ... So you and the compiler (that is, the narrow computer) request, Oneclass twoclass=new Oneclass () is a machine borrowed from the grammar, where the side Oneclass and Twoclass is a name difference, For example, your father likes to call his own car dear, then you drive the car, regardless of who, you can call it baby ... Oneclass can't be changed, because you have to tell the machine which car you borrowed ... And then you borrow it and you call it whatever you want .... Class below the method Ah, public properties can be borrowed from, like said the car has four wheels a steering wheel is the property, the method is that the car can be open, can also be inverted open .... So whether you want to be open or upside down, your premise needs to borrow the car to open ... Instantiation is the borrowing of cars ... The calling method is the operation after borrowing the car!        This is instantiation (from Baidu know)  

When defining a function in Python, how does self understand:

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.