[Python-ideas] Boolean behavior of None (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Thu Jan 17 15:32:43 CET 2013


Le Thu, 17 Jan 2013 15:10:45 +0200, Ilkka Pelkonen <ilkka.pelkonen at iki.fi> a écrit :

Hi Oleg, others, It's not that it can't be done, just that it does something you don't expect. I've been professionally working with C++ for nine years in large-scale Windows systems, and I do expect a boolean expression return a boolean value.

"and" is not a boolean operator, it is a shortcutting control flow operator. Basically, what you are looking for is:

flag = element.is_visible() if element else False

(or, more explicitly: flag = element.is_visible() if element is not None else False )

Regards

Antoine.



More information about the Python-ideas mailing list