Reputation: 23
For example:
def test(arg = False):
return arg, type(arg), isinstance(arg, int)
print(test())
will result in:
False, <class: 'bool', True>
The arg
variable is False
which is obviously a boolean
. The type()
function got it right but why does the isinstance()
function says that arg
is an int
? Is this a bug?
NOTE: I'm using Python 3.8.5
Upvotes: 1
Views: 913
Reputation: 95883
Because bool
objects are int
objects, in other words:
>>> issubclass(bool, int)
True
Or, put it another way:
>>> bool.mro()
[<class 'bool'>, <class 'int'>, <class 'object'>]
Upvotes: 4