September 2013
Intermediate to advanced
350 pages
9h 38m
English
Function isinstance reports whether an object is an instance of a class—that is, whether an object has a particular type:
| | >>> isinstance('abc', str) |
| | True |
| | >>> isinstance(55.2, str) |
| | False |
’abc’ is an instance of str, but 55.2 is not.
Python has a class called object. Every other class is based on it:
| | >>> help(object) |
| | Help on class object in module builtins: |
| | |
| | class object |
| | | The most base type |
Function isinstance reports that both ’abc’ and 55.2 are instances of class object:
| | >>> isinstance(55.2, object) |
| | True |
| | >>> isinstance('abc', object) |
| | True |
Even classes and functions are instances of object:
| | >>> isinstance(str, ... |
Read now
Unlock full access