Use of Python classes (class definitions, constructors, class properties, methods)

Source: Internet
Author: User

Note: Here only describes the use of methods, the concept of specific classes do not embarrass me this lazy person.

In a word, the programming language is just a tool, will be used on the line, easy to use. To break the casserole ask the end, I think it is necessary to study C, assembly, electronic links and so on.

1 classCLTDY:#define the class and start with a name2n = 1000#class properties, variables within a class3     def __init__(self,name,age,profession='IT workers'):#constructors, classes receive external incoming parameters all by constructors4Self.name =name5Self.age = Age6Self.profession =Profession7     defPrinting_name (self):#methods of the class8         Print('My name is:%s'%self.name)9     defprinting_age (self):Ten         Print("my Age:%s"%self.age) One     defPRINTING_PFSN (self): A         Print("My occupation:%s"%self.profession) -  -Test = Cltdy ('Sober', 25,'DevOps')#class, passing arguments to the class, passing in parameters that can be many but not less than the arguments of the class constructor (except for the self argument, self is the variable name that is instantiated into the class) the Print("This is the memory address after the class instantiation:%s"%test) -Test.printing_name ()#calling methods in a class after instantiation -Test.name ='Moon'    #You can modify the values of the parameters in the constructor - Test.printing_name () + TEST.PRINTING_PFSN () - Print(TEST.N) +TEST.N = 2000#Modify class properties to take effect only for test instantiation A Print(TEST.N,'\n====================') at  -T2 = Cltdy ('Jack', 22,'Student')#instantiate class object, name T2 - Print(T2.N) -T2.printing_age ()

Use of Python classes (class definitions, constructors, class properties, methods)

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.