Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The = symbol in Python is a delimiter used to form assignment statements, binding a name (or target) to an object reference. Unlike in statically typed languages where assignment is an operator that evaluates to a value, Python’s = forms a statement that does not return a value. It creates or updates an entry in the current namespace, mapping a symbolic identifier to an object’s memory address in the heap.

Syntax

target = "expression"

Statement vs. Expression

Because = forms a statement rather than an expression, it cannot be used inline within other operations. Attempting to use = where an expression is expected results in a SyntaxError. This strict separation prevents accidental assignments in conditional logic.
x = 1  # Valid assignment statement


# The following conceptual code would raise a SyntaxError if uncommented:

# if x = 1:

#     pass

Evaluation Mechanics

An assignment statement evaluates the Right-Hand Side (RHS) expression first, then binds the resulting object to the Left-Hand Side (LHS) targets strictly from left to right.
  1. RHS Evaluation: The expression is fully evaluated to yield a single object in memory.
  2. LHS Binding: The target identifier(s) are bound to the memory address of the evaluated RHS object.
If the LHS name already exists in the current scope, the = delimiter rebinds the name to the new object. This decrements the reference count of the previously bound object, which flags it for garbage collection if the count reaches zero.

Reference Binding

Because = assigns memory references rather than copying underlying data, assigning one variable to another results in both names pointing to the exact same object.
a = [1, 2, 3]
b = a          # 'b' is bound to the same list object as 'a'


# Verification of identical memory addresses
assert id(a) == id(b) 

Syntactic Variations

The = delimiter supports several structural patterns for binding multiple targets simultaneously: Chained Assignment Binds multiple targets to the exact same object reference in a single statement. Target binding occurs strictly left-to-right. In the following example, Python evaluates the string, binds the reference to x, then to y, and finally to z.
x = y = z = "singleton_string"

assert id(x) == id(y) == id(z)
Iterable Unpacking Maps elements from an evaluated iterable on the RHS to a corresponding sequence of targets on the LHS. The number of targets must strictly match the length of the iterable unless a starred expression (*) is utilized to capture remaining items.

# Standard unpacking
first, second = (10, 20)


# Starred unpacking (PEP 3132)
head, *tail = [1, 2, 3, 4]

assert head == 1
assert tail == [2, 3, 4]
Attribute and Item Assignment When the LHS is an object attribute or a collection index/slice, the = delimiter does not modify the local namespace. Instead, it invokes the object’s underlying mutation dunder methods (__setattr__ or __setitem__). While Python’s data model resolves the __setattr__ method lookup on the class rather than the instance, the actual assignment operation (via the default object.__setattr__) writes the assigned value directly into the instance dictionary (__dict__).
class Container:
    pass

obj = Container()
collection = [0, 0, 0]
value = 42
index = 1


# Attribute assignment
obj.attribute = value      

# Semantically invokes: type(obj).__setattr__(obj, 'attribute', value)

# The default implementation writes directly to the instance dictionary:
assert obj.__dict__['attribute'] == 42


# Item assignment
collection[index] = value  

# Semantically invokes: type(collection).__setitem__(collection, index, value)
assert collection[1] == 42
Master Python with Deep Grasping Methodology!Learn More