On this page

Variables and Data Types

Published on August 17, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

What Variables Are​

A variable is a name that refers to a value stored in memory. Variables allow a program to store information, reuse it, and modify it as needed. In Python, creating a variable does not require declaring its type. You assign a value, and Python determines the type automatically.


message = "Hello"

count = 3

A variable name should be descriptive and follow Python’s naming rules: use letters, digits, and underscores; do not start with a digit; avoid spaces; and use lowercase with underscores for readability.


first_name = "Alice"

age = 21

_country_of_birth = "UK" # starting underscores are valid too

uncle1 = "Bob"

uncle2 = "James"

COUNTRY_CODE = "UK" # Exception: although non-mandatory, values which should remain constant are often declared in all uppercase letters

first name = "Alice"

1st_country_visited = "Spain"

firstName = "Alice" # uppercase letters and no underscores for readability

DateOfBirth = "2015-02-16" # same as above

Assignment in Python​

Assignment uses the = operator. The value on the right is evaluated first, then stored under the name on the left.


x = 10

y = x + 5

After these instructions, x refers to 10 and y refers to 15. Assignment does not mean equality in the mathematical sense; it means “bind this name to this value.”

What Data Types Are​

A data type defines the kind of value stored in a variable and determines what operations can be performed on it. Python includes several built‑in types that you will use constantly.

Fundamental Python Data Types​

Integers (int)​

Integers represent whole numbers, positive or negative.


age = 30

temperature = -5

Floating‑Point Numbers (float)​

Floats represent numbers with decimal points.


price = 19.99

ratio = 0.5

Strings (str)​

Strings represent text. They are enclosed in quotes.


name = "Alice"

greeting = "Welcome to Python"

Strings support operations such as concatenation and repetition.


full = name + " Smith"

line = "-" * 20

Booleans (bool)​

Booleans represent truth values: True or False.


is_active = True

is_admin = False

Booleans often appear in conditions and comparisons.

None (NoneType)​

None represents the absence of a value. It is used when a variable exists but does not yet hold meaningful data.


result = None

Dynamic Typing​

Python uses dynamic typing. A variable’s type is determined at runtime and can change if you assign a new value of a different type.


value = 10

value = "ten"

warning

This flexibility is powerful but requires discipline. You must keep track of what type a variable is expected to hold to avoid errors.

info

Assigning and validating the correct variable types is covered in a separate article on type hints and type validation in a later module.

Inspecting Types​

You can check the type of a value using the type() function.


x = 42

print(type(x))

This is useful when learning or debugging.

Why Variables and Data Types Matter​

Variables and data types form the foundation of every Python program. They determine how information is stored, manipulated, and interpreted. Understanding them clearly ensures that later topics—such as expressions, control flow, functions, and data structures—will be easier to learn and apply.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Running Your First Script

Next

Input and Output