Python Assignment

Python assignment is done with =, the assignment operator.

>>> x = 3
>>> x
3

You can assign a variable the results of an operation:

>>> x = 3 + 8
>>> x
11
>>> x = 3 > 1
>>> x
True

You can assign multiple variables at once like so:

>>> x = y = 3
>>> x
3
>>> y
3
>>> x, y = 3, 5
>>> x
3
>>> y
5

You can’t assign to a literal value:

>>> 3 = 5
  File "<stdin>", line 1
SyntaxError: can't assign to literal
>>> [3, 2] = 5
  File "<stdin>", line 1
SyntaxError: can't assign to literal