Python Assignment: Understanding Multiple Assignments and Unpacking

Assignment Statements and the Assignment Operator
One of the most powerful programming language features is the ability to create, access, and mutate variables.In Python, a variable is a name that refers to a concrete value or object, allowing you to reuse that value or object throughout your code.
The Assignment Statement Syntax
To create a new variable or to update the value of an existing one in Python, youll use an assignment statement. This statement has the following three components:

A left operand, which must be a variable
The assignment operator (=)
A right operand, which can be a concrete value, an object, or an expression

Heres how an assignment statement will generally look in Python:

# This script demonstrates the use of an assignment statement in Python

# First, we define a variable named "variable" and assign it a value of 5
variable = 5 # "variable" is the left operand, "=" is the assignment operator, and 5 is the right operand

# Next, we define a variable named "expression" and assign it a value of 10
expression = 10 # "expression" is the left operand, "=" is the assignment operator, and 10 is the right operand

# Now, we can use the "variable" and "expression" variables in an expression
result = variable + expression # "result" is the left operand, "=" is the assignment operator, and "variable + expression" is the right operand

# Finally, we print the result of the expression
print(result) # "print" is a built-in function that displays the value of the given expression on the screen

To execute an assignment statement like the above, Python runs the following steps:

Evaluate the right-hand expression to produce a concrete value or object. This value will live at a specific memory address in your computer.
Store the objects memory address in the left-hand variable. This step creates a new variable if the current one doesn’t already exist or updates the value of an existing variable.

The second step shows that variables work differently in Python than in other programming languages.In Python, variables aren’t containers for objects. Python variables point to a value or object through its memory address. They store memory addresses rather than objects.
This behavior difference directly impacts how data moves around in Python, which is always by reference. In most cases, this difference is irrelevant in your day-to-day coding, but its still good to know.
The Assignment Operator
The central component of an assignment statement is the assignment operator. This operator is represented by the = symbol, which separates two operands:

SICORPS