(python 2.7.8)
I\'m trying to make a function to extract integers from a mixed list. Mixed list can be anything but the e.g. I\'m going with is:
test
Apparently bool is a subclass of int:
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(42, int)
True
>>> isinstance(True, int)
True
>>> isinstance('42', int)
False
>>> isinstance(42, bool)
False
>>>
Instead of isinstance(i, int)
, you can use type(i) is int
or isinstance(i, int) and not isinstance(i, bool)
.