The plain = operator binds a name to a value — technically to an object reference, since Python variables are labels rather than fixed memory slots. Compound assignment operators like += combine an arithmetic operation with the assignment, so x += 1 is roughly shorthand for x = x + 1 — though for mutable objects like lists, += can mutate in place rather than create a new object, a subtle but important distinction. Python also supports multiple and chained assignment, like unpacking two values at once or assigning the same value to several names in one statement.
1Understanding Assignment Operators
The plain = operator binds a name to a value — technically to an object reference, since Python variables are labels rather than fixed memory slots. Compound assignment operators like += combine an arithmetic operation with the assignment, so x += 1 is roughly shorthand for x = x + 1 — though for mutable objects like lists, += can mutate in place rather than create a new object, a subtle but important distinction. Python also supports multiple and chained assignment, like unpacking two values at once or assigning the same value to several names in one statement.
For a list, x += [item] mutates the list in place, while x = x + [item] always creates a brand-new list — this matters if other variables also reference the original list.
count = 0
count += 1
count += 1
print(count)2Practical Example
Here is a real-world application of Assignment Operators showing how it is used in production Python code.
original = [1, 2]
alias = original
alias += [3]
print(original)
print(alias is original)3Best Practices
Follow these guidelines when working with Assignment Operators:
1. Use compound operators like += for readability when updating a variable based on its own value
2. Be aware that += on a list mutates in place, unlike += on an int, str, or tuple, which always creates a new object
3. Use tuple unpacking for swaps instead of a manual temporary variable
Tip: For a list, x += [item] mutates the list in place, while x = x + [item] always creates a brand-new list — this matters if other variables also reference the original list.
count = 0
count += 1
count += 1
print(count)