python6.1 create classes

Dog class (Object):
type1 = "pet" class variables #
# initialize method
DEF __init __ (Self, name, Age, Color):
self.name = name # variable strength
self.age = Age
self.color = Color

# ordinary method
EAT DEF (Self):
Print (self.name, "the gnawing on a bone!")

DEF rUN (Self, Speed): # can join their own characteristics, such as: Speed
Print (self.color, self.name, "in the fast run ! speed: "speed)

DEF Sui (Self):
Print (self.age"! years old, the old dog ")

# instantiate an object
dog = dog (" rhubarb ", 4" black ") hidden # formula delivery self: dog At this time a total of four variables.
Print (dog.age) # initialization method to use variables receiving
dog.eat () # conventional method can be directly output
dog.run ( "5m / S")
dog.sui ( )

 

Guess you like

Origin www.cnblogs.com/lma0702/p/11110804.html