On this python doc page it says:
Like its identity, an object’s type is also unchangeable.
And I try this script,
#!python3
class Foo:
num = 1
pass
class Bar:
num = 2
pass
f1,f2= Foo(), Foo()
f2.__class__ = Bar
print( type(f1), type(f2), f1.num, f2.num )
The result shows:
<class '__main__.Foo'> <class '__main__.Bar'> 1 2
I think I changed the type
of f2
.
What's wrong, What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…