class CricketFan(PartyAnimal): points = 0 def six(self): self.points = self.points + 6 self.party() print(self.name, "points", self.points) s = PartyAnimal("Sally") s.party() j = CricketFan("Jim") j.party() j.six() print(dir(j))
from party import PartyAnimal class CricketFan(PartyAnimal): points = 0 def six(self): self.points = self.points + 6 self.party() print(self.name, "points", self.points) s = PartyAnimal("Sally") s.party() j = CricketFan("Jim") j.party() j.six() print(dir(j)) # Code: http://www.py4e.com/code3/party6.py
from party import PartyAnimal class CricketFan(PartyAnimal): points = 0 def six(self): self.points = self.points + 6 self.party() print(self.name,"points",self.points) s = PartyAnimal("Sally") s.party() j = CricketFan("Jim") j.party() j.six() print(dir(j))
/intl/lv/about.html https://www.google.com/setprefdomain?prefdom=LV&prev=https://www.google.lv/&sig=K_StfPL59WvUc1bIDQgdDPX4csJl0%3D /intl/lv/policies/privacy/ /intl/lv/policies/terms/ >>> class PartyAnimal: x = 0 >>> class PartyAnimal: x = 0 def party(self): self.x += 1 print('So far',self.x) >>> an = PartyAnimal() >>> an.party() So far 1 >>> an.party() So far 2 >>> an.party() So far 3 >>> PartyAnimal.party(an) So far 4 >>> count = dict() >>> an.party() So far 5 >>> self.x += 1 Traceback (most recent call last): File "<pyshell#43>", line 1, in <module> self.x += 1
from party import PartyAnimal class NewPartySpecies(PartyAnimal): points = 0 name = '' def __init__(self, point=0, nam='tempNewAnimal'): self.name = nam self.points = point print("I am alive, Name:", self.name, " and I am New") def six(self): self.points += 6 print(self.name, " has points : ", self.points) self.party(6) def four(self): self.points += 4 print(self.name, " has points : ", self.points) self.party(4) def __del__(self): print("You killed me, I was New!!!") if __name__ == '__main__': an = PartyAnimal(0, "OldAnimal_1") anNew = NewPartySpecies() an.party()
#1 class PartyAnimal: x = 0 def party(self): self.x = self.x + 1 print("So far", self.x) an = PartyAnimal() an.party() an.party() an.party() PartyAnimal.party(an) from party import PartyAnimal
from party import PartyAnimal class CricketFan(PartyAnimal): """docstring for CricketFan""" points = 0 def six(self): self.points = self.points + 6 self.party() print(self.name, 'points', self.points) x = PartyAnimal('Xi') x.party() j = CricketFan('Jiang') j.six() print(dir(j))
from cricket import CricketFan from party import PartyAnimal s = PartyAnimal('Sally') s.party() print(dir(s)) j = CricketFan('Jim') j.party() j.six() print(dir(j))