最佳答案
Can someone give me an explanation why isinstance()
returns True in the following case? I expected False, when writing the code.
print isinstance(True, (float, int))
True
My guess would be that its Python's internal subclassing, as zero and one - whether float or int - both evaluate when used as boolean, but don't know the exact reason.
What would be the most pythonic way to solve such a situation? I could use type()
but in most cases this is considered less pythonic.