Simple (non-branching) statement types are summarized below.
Assignment is a statement, not an operator, in Python. The general form is:
A variable name. The variable is bound to the value of the expression, that is, that variable now has that value, and any previous value it may have had is forgotten. For example, the statement
m to the integer value 0.
Part of a mutable
object that contains multiple values.
For example, if
L is a list,
would set the first element of
L to the string
As another example, suppose D is a dictionary. The statement
would associate key
"color" with value
"red" in that dictionary.
You can also assign to slices of a list:
L[1:3] = [10, 20, 30]
This statement would delete elements 1 and 2 of list L and replace them with three new elements 10, 20, and 30.
Finally, if an object
has an attribute
can assign a value of 73 to it using:
X.klarn = 73
If the expression
is a sequence, the destination can be a list of
variables, and the sequence is unpacked
into the variables in order. For example, this statement
x, y, z = [10, 11, 12]
x to 10,
y to 11, and
z to 12.