To create a variable in Python, you assign it a value with the equal sign. That single operation, the assignment statement, is how every piece of data in a Python program gets a name: a username typed into a form, a count from a loop, a setting read from a file. Once you are comfortable with assignment and the patterns built on top of it, you can focus on solving problems instead of syntax.
If you have read the introduction to Python variables, you already know a variable is a name that points to an object in memory. This article goes deeper into creating those names: the basic syntax, assigning the result of an expression, optional type hints, and using None as a placeholder when a value is not known yet.
The assignment statement
An assignment statement has a variable name on the left of the equal sign and a value on the right. Python evaluates the right side first, then makes the left side name point at whatever that side produced:
name = "Rowan"
age = 29
price = 12.99Each line creates one variable. The name itself carries no type information. Python remembers the type on the object, not on the name, which is why you can build values up across several lines without declaring anything in advance:
base_price = 100
tax_rate = 0.08
tax = base_price * tax_rate
total = base_price + taxThe third line reads the first two values, multiplies them, and assigns the result to tax. The fourth line adds the base price and the tax together and assigns the sum to total. At no point do you reserve memory or state a type. Python resolves the right side of each line before moving to the next.
Assigning expressions and function results
The right side of an assignment is not limited to literal values. It can be arithmetic, a string operation, or a call to a function you wrote yourself, and Python always finishes evaluating it before the assignment happens. This ordering is why counter = counter + 1 works rather than being a contradiction: Python reads the current value first, computes the new one, and only then rebinds the name.
full_name = "Alex" + " " + "Morgan"
square = 7 ** 2
user_data = fetch_user_profile(user_id)
display_name = user_data["name"]The first line concatenates three strings. The second raises 7 to the power of 2. The third calls a function once and stores its return value, so the fourth line can pull a field out of that stored result without calling the function again. Storing a result you plan to reuse is one of the most common reasons to create a variable in the first place, since recomputing it every time would be slower and could return different data if the underlying source changed between calls.
Type hints and the None placeholder
Python does not require type annotations, but it accepts them as documentation. A hint is a colon and a type after the name, and the interpreter reads it without enforcing it at runtime:
score: int = 0
username: str = "guest"Editors and dedicated type checkers use these hints to warn you about mismatches before the program ever runs, but assigning a string to score later would not raise an error from Python itself. For beginner scripts, hints are optional and many developers add them gradually as a project grows.
Sometimes you need a variable to exist before its real value is known, such as a result variable at the top of a function. Assign None in that case. It is Python's object for "nothing here yet," distinct from zero or an empty string, and you can check for it later with if result is None: to decide whether real data has arrived.
Assignment is not equality
A single equal sign means "make the left name refer to the right value." A double equal sign means "are these two values equal." Confusing them is a common beginner mistake, and Python guards against the worst version of it: writing if value = 10: is a syntax error rather than a silent bug, unlike in some other languages where that line would quietly assign 10 and then treat it as true. This distinction becomes automatic with practice, but it is worth checking twice in the first few weeks, especially inside conditions where a single missing equal sign changes what the line does entirely.
Names are case-sensitive
Python treats uppercase and lowercase letters as different characters, so score, Score, and SCORE are three separate variables. You will rarely create names that differ only by case on purpose, but a typo like writing Score when you meant score silently creates a new variable instead of raising an error, which is a frequent source of confusing bugs. Most editors highlight a name the first time it appears, which helps you catch this kind of typo before it turns into a debugging session. The full naming conventions, including the community's lowercase-with-underscores style, are covered in the next article.
What comes next
Assignment is the mechanism; naming is the craft that makes assigned values easy to read later. The next article covers Python's variable naming rules: which characters are allowed, which words are reserved, and the conventions that keep code readable across a team. After that, you will learn how to reassign a variable as your program's state changes and how to assign multiple variables at once for cleaner code. Each of those articles assumes you are comfortable with the assignment statement covered here, so it is worth returning to this page if a later example ever feels unfamiliar.
Rune AI
Key Insights
- Use the equal sign to assign a value to a name, creating the variable.
- Python evaluates the entire right side before it touches the left side.
- The right side can be a literal, an expression, or a function call.
- Type hints document an intended type but do not change what happens at runtime.
- Assign None as a placeholder when a variable needs to exist before its real value is known.
Frequently Asked Questions
What is the assignment operator in Python?
Can I assign a variable without a value?
Does Python have constants like other languages?
Conclusion
Creating a variable in Python means picking a name and assigning a value with the equal sign. The right side is always evaluated first, which keeps assignment predictable and lets you build values up from expressions instead of only literals.
More in this topic
Python Variable Naming Rules
Learn Python's variable naming rules, including allowed characters, reserved keywords, PEP 8 conventions, and how to choose names that make your code readable.
Python Variables Explained
Understand what Python variables are, how they store and reference data, and why Python's variable model is different from other programming languages.
Reassign Variables in Python
Learn how to reassign Python variables to new values, how reassignment interacts with mutable and immutable types, and the patterns that keep your code predictable.