Variables and Data Types: Python Programming from Zero
Learn to store and display data in Python. This lesson covers declaring variables, assigning strings and integers, and printing output to the console.
Previously in this course, we covered Setting Up the Python Environment, where you configured your editor and executed your first script. Now that your environment is ready, we need a way to store the information your programs will process.
In programming, we use variables to act as labeled containers for data. Without them, our code would be static and unable to track changing information like user input or API responses.
Understanding Variables and Python Syntax
Think of a variable as a sticky note on a cardboard box. You write a name on the note (the variable name) and put something inside the box (the value). Python uses a straightforward syntax for this: variable_name = value.
This is called an assignment. The equals sign (=) doesn't mean "is equal to" in the mathematical sense; it means "take the value on the right and store it in the container on the left."
Essential Data Types
While Python can store many kinds of information, we’ll start with the two most common types you’ll use in our upcoming data-processing CLI:
- Strings (
str): Text data. They must be wrapped in quotes—either single ('hello') or double ("hello"). - Integers (
int): Whole numbers without decimals (e.g.,42,-10,0).
Worked Example: Storing and Printing Data
Let’s write a simple script that stores a user’s name and their age, then displays that information in the console using the print() function.
PYTHON# Declare a string variable user_name = "Alex" # Declare an integer variable user_age = 28 # Print the variables to the console print(user_name) print(user_age)
When you run this, Python looks up the labels user_name and user_age, retrieves the values stored inside them, and sends them to your terminal.
Hands-on Exercise: Building the Foundation
We are going to start the groundwork for our CLI tool. Open your code editor and create a new file named tracker.py.
- Create a variable named
project_nameand assign it a string describing a project (e.g., "Data Collector"). - Create a variable named
version_numberand assign it an integer (e.g., 1). - Use the
print()function to display both variables.
Your output should look like this:
TEXTData Collector 1
Common Pitfalls
Even experienced engineers occasionally trip over these three common issues:
- Case Sensitivity: Python is case-sensitive.
user_nameandUser_nameare treated as two entirely different variables. Always usesnake_case(all lowercase with underscores) for variable names to keep your code readable and consistent. - Forgetting Quotes: If you write
name = Alexwithout quotes, Python will look for a variable namedAlexinstead of treating it as text. This will trigger aNameError. - Reassignment Confusion: You can change the value of a variable at any time. If you write
x = 5thenx = 10, the number 5 is gone. Be careful not to overwrite data you still need.
FAQ
Can I store decimals in variables?
Yes, those are called floats. We will cover them in the next lesson when we discuss arithmetic.
Does it matter if I use single or double quotes for strings?
In Python, no. You can use 'hello' or "hello" interchangeably. Just be consistent within your project.
What is the maximum size of an integer? Python integers have arbitrary precision, meaning they can be as large as your computer's memory allows. You don't need to worry about "overflow" errors common in languages like C.
Recap
In this lesson, you learned that variables are the backbone of data storage. By using simple Python syntax for assignment and understanding the difference between data types like integers and strings, you have taken the first step toward building dynamic programs. You now have the ability to hold data in memory and output it to the user.
Up next: Arithmetic Operations, where we will perform calculations on these variables to make our CLI tool actually process data.
Work with me

AI Automation & Agentic Workflow Development
Automate the repetitive work eating your time — content pipelines, data workflows, and agentic AI tasks that run themselves.

React & Next.js Dashboard / Admin UI Development
A clean, data-rich dashboard UI in React or Next.js — charts, tables, and real-time data that your users will actually enjoy using.

