Skip to content
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

isinstance and bool #33

Open
y47bears opened this issue Jan 12, 2017 · 1 comment
Open

isinstance and bool #33

y47bears opened this issue Jan 12, 2017 · 1 comment

Comments

@y47bears
Copy link

Why doesn't isinstance(param, bool) work? The error shows that the function is evaluating as the int 1 instead of as a boolean.

@JayBk
Copy link

JayBk commented Jan 14, 2017

Because True and False is also 1 and 0.. Which is an int... xD

It wont work the other way around though using isinstance...

For example:

>>> isinstance(True, int)
True
>>> isinstance(False, int)
True
>>> True == 1
True
>>> False == 0
True
>>> 1 == True
True
>>> 0 == False
True
>>> dd = True
>>> if dd == 1:
	print('True or 1... Same difference')

True or 1... Same difference

BUT then if you try checking if 1 or 0 is a bool using isinstance it gives False:

>>> isinstance(1, bool)
False
>>> isinstance(0, bool)
False

Does that make sense or did I just confuse you? Lol

Edit: Also, HINT: Since when using isinstance((True or False), int) returns True but isinstance(ANYNUMBER, bool) returns False, which one do you need to make sure goes first so that when True or False is passed it if correctly evaluated as a bool?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants