assignment
In Python, an assignment is a fundamental operation that binds values to variables. Assignments can also modify attributes or items of mutable objects, as in point.x = 10 or numbers[0] = 10.
By using the assignment operator (=), you can assign the result of an expression or a concrete value to a variable.
Python also supports augmented assignment, which combines a binary operation with an assignment (count += 1). Annotated assignment pairs a type annotation with an optional assignment (count: int = 0).
Python is a dynamically typed language, so you don’t need to explicitly declare variable types. Instead, a variable is just a name bound to an object, and the object itself carries the type.
Understanding assignments is key to harnessing Python’s power, as it allows you to manipulate data efficiently.
Examples
Here are some examples of how assignment works in Python:
>>> # Assigning an integer to a variable
>>> x = 10
>>> x
10
>>> # Assigning a string to the same variable
>>> x = "Hello, Python!"
>>> x
'Hello, Python!'
>>> # Assigning the result of an expression
>>> y = x + " How are you?"
>>> y
'Hello, Python! How are you?'
In these examples, you can see how a single variable, x, can hold values of different types at different points in the code.
Related Resources
Tutorial
Python's Assignment Operator: Write Robust Assignments
In this tutorial, you'll learn how to use Python's assignment operators to write assignment statements that allow you to create, initialize, and update variables in your code.
For additional information on related topics, take a look at the following resources:
- Variables in Python: Usage and Best Practices (Tutorial)
- Python Assignment Expressions and Using the Walrus Operator (Course)
- Variables in Python (Course)
- Working With Global Variables in Python Functions (Course)
- The Walrus Operator: Python's Assignment Expressions (Tutorial)
- Python's Assignment Operator: Write Robust Assignments (Quiz)
- Variables in Python: Usage and Best Practices (Quiz)
- The Walrus Operator: Python's Assignment Expressions (Quiz)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Sept. 27, 2026