Python supports normal assignment, chained assignment, incremental assignment, but does not support expression assignment.
Normal Assignment: x =1
Increment assignment: x = 1; x + = 1
Chain Assignment---Assign values to several variables at the same time, as in the example below
>>> x = 1 >>> x = y = x + 1 >>> x, y (2, 2) |
|
In other languages, such as C, expressions are supported, meaning that the expression has a return value, such as x = 1;y = (x + = 1), then the value of x, Y is 2, what happens in Python?
>>> x = 1 >>> y = (x + = 1) Syntaxerror:invalid syntax >>> y = (x = x+1) Syntaxerror:invalid syntax >>> |
The above example shows a problem:Python does not support expression assignment.
Python also supports multivariate assignments, in a sentence, assigning values to multiple variables, eg:x, y, z =, "xyz" (General x =1;y =2; z = "xyz"), or using an expression like this
>>> (x, y, Z) = (3,4,5) >>> x 3 >>> y 4 >>> Z 5 >>> |
The difference between an expression assignment and a chained assignment in Python