list comprehension problem

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Oct 30 05:28:14 CET 2009


On Thu, 29 Oct 2009 23:10:39 -0400, Nick Stinemates wrote:

>> Some objects are singletons, ie there's only ever one of them. The most
>> common singleton is None. In virtually every other case you should be
>> using "==" and "!=".
> 
> Please correct me if I am wrong, but I believe you meant to say some
> objects are immutable, in which case you would be correct.


No, being immutable does not imply there is only one of it. Strings and 
ints are immutable:

>>> a = 987654
>>> b = 987654
>>> a == b
True
>>> a is b
False


However, None, True, False, NotImplemented, and most (all?) builtin 
functions are singletons:

>>> f = len; g = len
>>> f is g
True
>>> x = None; y = None
>>> x is y
True



-- 
Steven



More information about the Python-list mailing list