name = "OutOfClass"
class MyClass:
name = "InTheClass"
var1 = [name for _ in range(3)]
var2 = [name]*3
obj = MyClass()
print(obj.name)
print(obj.var1)
print(obj.var2)
When i run this code in vscode i got:
for print(obj.var1)
['OutOfClass', 'OutOfClass', 'OutOfClass']
and for print(obj.var2)
['InTheClass', 'InTheClass', 'InTheClass']
I expected the output of both codes to be the same and use internal name
variable.
Why this happened???
I multiple run this code and result don't change.