Hello Sir/Mam,
In the below code why do we define a function within the class and then pass a argument. Also, please make me learn on why it is important to create an object?
Also, why the Python interpretor doesn’t go sequentially on throwing outputs…?
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()
print(“skip”)
so = PartyAnimal()
so.party()
an.party()
an.party()
#Problem: The Below Code isn’t working for me…
class PartyAnimal:
x = 0
name = “”
def init (self, nam):
self.name = nam
print (self.name,“Constructed”)
def party(self):
self.x = self.x + 1
print (self.name,"Party Count", self.x)
s = PartyAnimal(“Sally”)
s.party()
j = PartyAnimal(“Jim”)
j.party()
s.party()