+ 1

why the answer is 1 ?

class Animal: i=0 def __init__(self,name): self.name = name Animal.i+=1 class Cat(Animal): i=Animal.i def __init__(self,name): self.name = name Cat.i +=1 sylvester = Cat('Sylvester') print(Cat.i)

17th Jun 2020, 10:47 AM
Vikash Kumar
Vikash Kumar - avatar
1 Answer
+ 2
Because Animal.i = 0 Cat.i = Animal.i Then look what happens when a cat is made
17th Jun 2020, 11:01 AM
Slick
Slick - avatar