Favorite non-python language trick?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Jun 27 13:25:19 CEST 2005


On Sun, 26 Jun 2005 23:22:00 -0500, Terry Hancock wrote:

>> You need to differentiate
>>    a = b = 1
>> from
>>    a = b == 1
> 
> Okay, I see what you mean.  I can't ever recall having needed the
> second form, though.
> 
> Of course, you could still do assignment like this:
> 
> a, b = (1,)*2
> 
> But I guess that's not exactly elegant. ;-)

In general that is not the same thing as a = b = obj.

py> a, b = ([], [])
py> a.append(1)
py> b
[]
py> a = b = []
py> a.append(1)
py> b
[1]


-- 
Steven.




More information about the Python-list mailing list