4

After looking at these two questions,

I had this question:

How does a = b = c = 42 propagate 42 to the left without returning the value at each step?

Community
  • 1
  • 1
sgarg
  • 2,180
  • 4
  • 26
  • 41

3 Answers3

8

Because of a special exception in the syntax, carved out for that exact use case. See the BNF:

assignment_stmt ::=  (target_list "=")+ (expression_list | yield_expression)

Note the (target_list "=")+.

icktoofay
  • 122,243
  • 18
  • 242
  • 228
3

Chained assignment in this manner does not require assignment to return a value. It is a special form of the assignment statement which binds the object to multiple names.

Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
1

It's a python feature. From Python Tutorial:

A value can be assigned to several variables simultaneously:

>>> x = y = z = 0  # Zero x, y and z
>>> x
0
>>> y
0
>>> z
0

Note that in fact, an assignment doesn't return any value. You cannot do this

a = b = (c = 2)
Christian Tapia
  • 32,670
  • 6
  • 50
  • 72