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)