# Classes and objects, classes are categories, types, object-oriented design is the most important concept # object is a combination of characteristics and skills, # class is a set of objects with similar characteristics skill combination # For example: a person is class, and I am an object, hands, feet, my features, # eating place, sleep, study, I acquired skills # in programming class also has two features, # data attributes, function attributes. class people (): DEF the __init__ (Self, name, Age, Gender): # data class attribute defines the self.name = name self.age = Age self.gender = Gender # function attribute class DEF EAT (Self): Print ( " % S was eating place "% The self.name) # sides of the object itself self here # pass the required parameters init, instantiate an object PEO = people ( " wangcong " , 21 is, ' MALE ' ) # object data attributes Print (peo.name) # function properties of the object peo.eat () # we have found the object using a function similar to our property before using strings, lists the same way as # in fact, the string str is a class, we have defined the string "hello" is a # object # function attribute class is bound to the object, all objects and data attributes shared PEO1 = people ( " Enchantress " ,. 8, ' FMALE ' ) PEO2 = people ( " Ritz ",. 8, ' MALE ' ) Print (ID (peo1.age)) Print (ID (peo2.age)) Print (peo1.eat) Print (peo2.eat)
# class special properties,
# Name print (people .__ name__) # class (string)
# Print (people .__ doc__) # class docstring
# print (people .__ base__) The first class of the parent class #
# print (people .__ bases__) All tuples # parent class consisting of
dictionary attributes # print (people .__ dict__) # class
module # print (people .__ module__) # where the class
# print (people .__ class__) # corresponding class is instantiated