An object is an instance (or not)?
Rustom Mody
rustompmody at gmail.com
Wed Jan 28 00:53:50 EST 2015
On Wednesday, January 28, 2015 at 10:55:32 AM UTC+5:30, Marko Rauhamaa wrote:
> Python itself has answers to your questions:
>
> >>> isinstance(3, int)
> True
> >>> isinstance("3", int)
> False
> >>> isinstance(int, type)
> True
> >>> isinstance(type, int)
> False
> >>> isinstance(type, type)
> True
> >>> isinstance(3, type)
> False
> >>> isinstance(int, 3)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: isinstance() arg 2 must be a type or tuple of types
> >>> isinstance(3, object)
> True
> >>> isinstance("3", object)
> True
> >>> isinstance(int, object)
> True
> >>> isinstance(type, object)
> True
> >>> isinstance(object, object)
> True
>
>
> Marko
neat
Maybe add also
>>> isinstance(type,object)
True
>>> isinstance(object,object)
True
>>> issubclass(object,type)
False
>>> issubclass(type,object)
True
>>> isinstance(object,type)
True
>>> issubclass(int,object)
True
More information about the Python-list
mailing list