New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bool variable isinstance of int #90049
Comments
Hello, Recently I observed that isinstance(x, int) returns True, even when x is defined as a bool. While I understand that internally, a bool is treated as an int with values 0 and 1; to me, this is a bit misleading that the python interpreter returns True when we perform the isinstance() check. May be I'm missing some deeper explanation. Could someone please shed some light on this. Has this been discussed by the community in the past. Thank you very much for reading this ticket. >>> x = True
>>> isinstance(x, int)
True |
This is the expected behavior. The bool type is a subtype of int. True is int 1 in disguise and False is int 0. >>> bool.__mro__
(<class 'bool'>, <class 'int'>, <class 'object'>)
>>> True == 1
True
>>> True == 2
False
>>> False == 0
True |
Hi noobie1000, This is not a general forum for asking questions about Python's design or language, this is for reporting bugs. There are many forums where you can ask "Why" questions and ask for the community to "shed some light on this", such as Reddit's r/python, the various mailing lists, Discuss, IRC, etc. In future please use them rather than the bug tracker. Regarding bool, you can start by reading this: https://www.python.org/dev/peps/pep-0285/ If that doesn't answer your questions, please feel free to take them to the many different forums here: https://www.python.org/community/forums/ |
Hello Steven, Sorry, this is my first ever post and was lost in the enormity of issues/documentation. Noted your points :) Thank you. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: