[Python-ideas] Please reconsider the Boolean evaluation of midnight
M.-A. Lemburg
mal at egenix.com
Thu Mar 6 12:22:47 CET 2014
On 06.03.2014 12:09, Antoine Pitrou wrote:
> Le 06/03/2014 12:04, M.-A. Lemburg a écrit :
>>
>> Writing
>>
>> if x: print ('x is None')
>>
>> or
>>
>> if x == None: print ('x is None')
>>
>> is wrong code.
>
> No it isn't.
>
>> None is a singleton, so you have to use the "is" operator, i.e.
>>
>> if x is None: print ('x is None')
>>
>> is the only correct way of testing for None.
>
> No it isn't. x == None is a perfectly well-defined way of doing it, even if it isn't the
> stylistically preferred one.
Depends on what kind of type x is and how that type implements
the comparison slots. It is perfectly well possible to define a
type that returns True for (x == None), even though x is not None :-)
>>> class C:
... def __eq__(self, other):
... return (other is None)
...
>>> o = C()
>>> o == None
True
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Mar 06 2014)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2014-04-09: PyCon 2014, Montreal, Canada ... 34 days to go
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list