python advanced object-oriented version of the original understanding of object-oriented by a question with you

The definition of a class

the Person class:
# Public property
animal = 'higher animals'
Soul = 'soul'
Language = 'language'
DEF the init (Self, Country, name, Sex, Age, the Height): # parameter
after the object obj is an instance #self address self object. is to call the method
self.c = Country
self.n = name
self.s = Sex
self.a = Age
self.H the Height =
Print (self.n, self.s, self.n)
DEF SLEEP ( self): # define a method of
print ( 'I want to eat')
DEF eAT (self): # define a method of
print (f '{self.n} eating') # format output
DEF Work (Self):
Print ( 'jobs')

Instantiating the object 4

obj = Person ( 'China', 'alex', 'unknown', 42,175)
obj2 = the Person ( 'USA', 'Wu', 'M', 35,160)
obj3 = the Person ( 'China', 'sub-text', ' M ', 35,160)
OBJ4 = the Person (obj.c, obj2.n, obj3.s, obj3.s, obj.H)

The fourth individual p4 class object attributes: p1 nationality, p2 name, p3 gender, p2 age, p3

Height.

obj.eat () # by calling the object method
obj2.eat ()
obj3.eat ()
Print (obj.animal)
Print (obj2.soul)
Print (obj3.language) by the method invocation, #
print (obj4 .__ dict __) # Print incoming values inside the init method

Guess you like

Origin www.cnblogs.com/strawberry-1/p/11291225.html