0
Why does it show 122 but not 123 when printing this code(hmp)???
class Hg: a=0 def __init__(self): Hg.a += 1 def __del__(self): Hg.a -= 1 a=Hg() print(a.a) b=Hg() print(b.a) a=Hg() print(a.a)
1 Resposta
+ 1
TCorn you have defined object a twice
class Hg: a=0 def __init__(self): Hg.a += 1 def __del__(self): Hg.a -= 1 a=Hg() print(a.a) b=Hg() print(b.a) a=Hg() print(a.a)