Testing the data type of a value
Alan Bawden
alan at csail.mit.edu
Mon May 13 10:33:28 EDT 2019
Luuk <luuk.vosslamber at gmail.com> writes:
...
> Maybe i should have asked this:
>
> What is the difference between 'type(5)==int' and 'isinstance(5,int)'
>
> and, if there is no difference why did someone invent 'isinstance()' ...
Look:
Python 3.6.6 (default, Aug 13 2018, 18:24:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(True, int)
True
>>> type(True) == int
False
>>> type(True)
<class 'bool'>
--
Alan Bawden
More information about the Python-list
mailing list