variable

A variable is a symbolic name that references an object stored in memory. When you assign a value to a variable, you create a reference to that value.

Variables are fundamental in Python because they allow you to store, modify, and retrieve data throughout your code. You can use variables to hold any type of data, such as numbers, strings, lists, or even more complex data structures like custom objects.

Python variables are dynamically typed, meaning you don’t have to explicitly declare the variable’s type. The Python interpreter automatically determines the type based on the value you assign to it. This dynamic nature allows for more flexible and readable code.

It’s highly recommended to use meaningful variable names to make your code more readable, understandable, and maintainable.

Example

Here’s an example of how you can create and use variables in Python:

Python
>>> # Create variables
>>> name = "Alice"
>>> age = 30
>>> height = 1.75

>>> # Access objects through variables
>>> print(f"{name} is {age} years old and {height} meters tall.")
Alice is 30 years old and 1.75 meters tall.

>>> # Reassign a variable
>>> age += 1
>>> print(f"Next year, {name} will be {age} years old.")
Next year, Alice will be 31 years old.

In this example, the variables name, age, and height reference objects of different types of data. To access the value, you just need to use the variable name. You can also assign a new value to an existing variable.

Tutorial

Variables in Python: Usage and Best Practices

In this tutorial, you'll learn how to use symbolic names called variables to refer to Python objects, and gain an understanding of how to effectively use these fundamental building blocks in your code to store, manipulate, and retrieve data.

basics python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated March 6, 2025 • Reviewed by Martin Breuss