天天看點

python普通指派、鍊式指派、複合指派不支援表達式指派

Python支援普通指派,鍊式指派,複合指派,但不支援表達式指派。

例子:

  1. 普通指派 x = 1
  2. 鍊式指派 x = y = 123
  3. 複合指派 i = 1;i += 1

課後習題有個經典的例子可以說明python不支援表達式指派:

(1)  x = ( y =1 )
>>> x = ( y = 1 )
 File "<stdin>", line 1
   x = ( y = 1 )
           ^
SyntaxError: invalid syntax



(2) x = 1; y = ( x += 1)
``
>>> x = 1
>>> y = (x += 1)
 File "<stdin>", line 1
   y = (x += 1)
           ^
SyntaxError: invalid syntax