Objects in Python

Ian Kelly ian.g.kelly at gmail.com
Wed Aug 22 20:10:08 EDT 2012


On Wed, Aug 22, 2012 at 5:58 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Those people are confused, then. Python is strongly typed: objects
> always know their type, the type is always exact, and the type of an
> object can't be changed.

Except when it can.

>>> class A: pass
...
>>> class B: pass
...
>>> a = A()
>>> type(a)
<class '__main__.A'>
>>> isinstance(a, B)
False
>>> a.__class__ = B
>>> type(a)
<class '__main__.B'>
>>> isinstance(a, A)
False
>>> isinstance(a, B)
True

Cheers,
Ian



More information about the Python-list mailing list