Python (14) class, method, object, instance

Source: Internet
Author: User

    • Class: Simply a collection of functions in which you define a number of functions;
    • Method: These are actually the functions you define.
    • Object: In simple terms, it is a variable that has multiple attributes (or sub-variables).
    • In the example below, Class Plus is a class, and the two functions nested within this class are called methods, but __init__ is only used to initialize the class, so it is not a method.
    • and Get_result This function is a method.
    • C1 and C2 are two instances, but they have a common attribute and template

Example of a class:

1 #!usr/bin/python2 #Coding=utf-83 classPlus:4     #Self is an object with two parameters inside the object self.a,self.b5     def __init__(self,a=0,b=0,c=0,d=0):6SELF.A =a7SELF.B =b8SELF.C =C9SELF.D =DTen     defGet_result (self): One         returnSELF.A +self.b A     defget_sum (self): -         returnself.b+SELF.D -  the  - if __name__=='__main__': -C1 = Plus (7,8)#C1 represents an example -RESULT1 = C1.get_result () +     Printresult1 # output results are   -C2 = Plus (0,4,5,9)#C2 is also an example +RESULT2 = C2.get_sum () A     PrintResult2# Output is the result of 

Python (14) class, method, object, instance

Related Article

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.