+ 1

How will this code work?

class Dog: legs = 4 def __init__(self, name, color): self.name = name self.color = color fido = Dog("Fido", "brown") print(fido.legs) print(Dog.legs) fido2 = Dog("Fido2", "brown2") fido2.legs = 5 print(fido2.legs) print(fido.legs) print(Dog.legs)

5th Sep 2016, 6:46 AM
Pradnesh
2 Answers
+ 1
define var class dog name fido2 with name fido2 and color is brown2 then you assing fido2'legs = 5 if you print(fido2.legs) , result is fido2'legs = 5 if you print(fido.legs) , result is fido'legs = 4 if you print(Dog.legs) , result is class dog'legs = 4
5th Sep 2016, 6:54 AM
beauty1234
0
thanks - its not a static variable then
5th Sep 2016, 7:06 AM
Pradnesh