Pages

Wednesday, August 14, 2013

Type checking in Python

Python's value has a type, however a variable can be assigned to any typed value.
>>> a = A()
>>> a is A
False
>>> id(a)
3567120
>>> id(A)
2377856

>>> id(type(a))
2377856

>>> type(a) is A
True

>>> a.__class__ is A
True

>>> isinstance(a, A)
True

No comments:

Post a Comment