简体   繁体   中英

Why is the isinstance() function not working?

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

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'>]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM