Favorite non-python language trick?

Robert Kern rkern at ucsd.edu
Sun Jun 26 07:11:18 EDT 2005


Terry Hancock wrote:
> On Sunday 26 June 2005 05:39 am, Torsten Bronger wrote:
> 
>>Hallöchen!
>>However, then you must forbid a=b=1 for assigning to two variables
>>at the same time.
> 
> Why?  It's already handled as an exception in the syntax.
> 
> In C, what you say makes sense, because "b=1" is an expression as
> well as an assignment. But I don't think Python reads it that way -- it 
> just has code to recognize multiple assignment as a statement. I think
> I remember reading that in the Language Reference or something.

You need to differentiate

   a = b = 1

from

   a = b == 1

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list