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,340
  • 5
  • 30
  • 42

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
  • 126,289
  • 21
  • 250
  • 231
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
  • 776,304
  • 153
  • 1,341
  • 1,358
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
  • 33,620
  • 7
  • 56
  • 73