why () is () and [] is [] work in other way?

Dave Angel d at davea.name
Sat Apr 21 09:21:50 EDT 2012


On 04/21/2012 09:02 AM, Bernd Nawothnig wrote:
> On 2012-04-20, dmitrey wrote:
>> I have spent some time searching for a bug in my code, it was due to
>> different work of "is" with () and []:
>>>>> () is ()
>> True
> You should better not rely on that result. I would consider it to be
> an implementation detail. I may be wrong, but would an implementation
> that results in
>
> () is () ==> False
>
> be correct or is the result True really demanded by the language
> specification?

You're correct, the behavior is undefined.  An implementation may happen
to produce either True or False.

>>>>> [] is []
>> False
> Same for that.

Here I have to disagree.  If an implementation reused the list object
for two simultaneously-existing instances, it would violate first
principles.

The distinction is simply that () is immutable, so the implementation
*may* choose to reuse the same one.



-- 

DaveA




More information about the Python-list mailing list