Query Order:
Object. Properties: First find from Object space, if not found, then from the class space to find, and then find, and then from the parent class to find ....
Class name. Properties: First find from this type of space, if not found, then from the parent class to find ....
Objects are independent of each other from objects.
Calculates how many objects an instance of a class instantiates.
Cases
Class Count:
Count = 0
def __init__ (self):
Count.count = Self.count + 1
Obj1 = Count ()
Obj2 = Count ()
Print (Count.count)
Count = 0
class Count:
Count = 0
def __init__ (self):
Pass
You can change the value of a static variable in my class by using the class name count.count = 6
Print (count.__dict__)
but cannot be changed by object can only refer to static variables in class
Obj1 = Count ()
Print (obj1.count)
Obj1.count = 6
combination: Encapsulates a property for an object of a class that is an object of another class.
Example
Version two:
Class Gamerole:
def __init__ (self, name, AD, HP):
Self.name = Name
Self.ad = AD
SELF.HP = HP
Def attack (Self,p):
P.HP = P.hp-self.ad
Print ('%s attack%s,%s lost%s blood, left%s blood '% (SELF.NAME,P.NAME,P.NAME,SELF.AD,P.HP))
def armament_weapon (Self,wea):
Self.wea = WEA
Class Weapon:
def __init__ (Self,name,ad):
Self.name = Name
Self.ad = AD
def fight (SELF,P1,P2):
P2.HP = P2.hp-self.ad
Print ('%s was hit with%s%s,%s lost%s blood, left%s blood ' \
% (P1.NAME,SELF.NAME,P2.NAME,P2.NAME,SELF.AD,P2.HP))
P1 = Gamerole (' Big Brother ', 20,500)
P2 = gamerole (' Indian ning ', 50,200)
Axe = Weapon (' kick ', 60)
Broadsword = Weapon (' Dragon Slayer Blades ', 100)
# Print (axe)
P1.armament_weapon (Axe) # equip Big Brother with kick this object.
# Print (P1.WEA)
# Print (p1.wea.name)
# Print (P1.WEA.AD)
P1.wea.fight (P1,P2)
Python 2018.7.24 class space, object space, query order, combination