Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why bool(None and None is None) is False?

If None and None returns None, (None and None is None) should return True, No?

Was debugging an app and noticed that it returns None

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Good question!

(None and None is None)

"is" has a priority, so None is None returns True

"and" executed after that, so None and True result in None

If you add parenthesis, you can make it work in another way:
((None and None) is None) returns True

You can find more info on that topic here:
https://docs.python.org/3/reference/expressions.html#operator-precedence

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading