why does this happen?

Carel Fellinger cfelling at iae.nl
Sun Feb 11 20:22:05 EST 2001


> In C assignment is an expression: the value of the expression a=1 is 1.
> In Python, assignment is not an expression: print a=1 is an error.
> Python allows assignment to several variables "simultaneously" (that's
> what the Python Tutorial says) with the form a = b = 1. I don't see
> anything in the Language Reference that says what order the assignments
> are actually carried out, but from your experiment and my own it looks

>From the Python Language Reference 1.5.2:

          next up previous Python Reference Manual contents index

   Next: 6.4 The pass statement Up: 6. Simple statements Previous: 6.2
   Assert statements
     _________________________________________________________________

                           6.3 Assignment statements

   Assignment statements are used to (re)bind names to values and to
   modify attributes or items of mutable objects:

assignment_stmt: (target_list "=")+ expression_list
target_list:     target ("," target)* [","]
target:          identifier | "(" target_list ")" | "[" target_list "]"
               | attributeref | subscription | slicing

   (See section 5.3 for the syntax definitions for the last three
   symbols.)

   An assignment statement evaluates the expression list (remember that
   this can be a single expression or a comma-separated list, the latter
   yielding a tuple) and assigns the single resulting object to each of
   the target lists, from left to right.

So it is, from left to right:) 
-- 
groetjes, carel



More information about the Python-list mailing list