Learning Python starts with three simple building blocks: variables, data types, and operators. These are the basics you need before moving to functions, loops, or more advanced topics. Let’s go step by step.
📝 If You Want to Practice the Code
If you plan to practice the Python code mentioned within this blog post, you’ll need a working Python environment. You can execute the commands in one of the following ways (choose only one option):
- From a Python prompt in your terminal or command line – see Getting Started with Python and Virtual Environment in Python and How to Set One Up
- Using Miniconda and Jupyter Notebook – see How to Install and Set Up Miniconda and Install Jupytor Notebook Windows, How to Install and Set Up Miniconda on MacOS, How to Install and Set Up Miniconda on Linux (Ubuntu), and Getting Started with Jupyter Notebooks.
- On Google Colab (browser-based, no installation required) – see Getting Started with Google Colab.
- Through VS Code – see Setting Up VS Code for Python Development.
👉 Choose whichever environment you’re most comfortable with. If you haven’t set up Python yet, start with one of the installation posts before trying the examples here.
🔹 Variables
A variable is like a container that stores information for later use.
In Python, you don’t need to declare the type — it’s decided automatically.
# Examples of variables
name = "Alice" # A string
age = 25 # An integer
height = 5.6 # A float
is_student = True # A boolean
👉 Think of variables as “labels” pointing to values.
🔹 Data Types
The most common data types in Python are:
- Numbers
int→ whole numbers (10, -5)float→ decimals (3.14, -0.5)
- Strings
- Text inside quotes:
"Hello"or'World' - Strings can be combined or sliced:
greeting = "Hello" print(greeting + " World") # Hello World print(greeting[0]) # H
- Text inside quotes:
- Booleans
- Either
TrueorFalse - Often used in conditions:
is_raining = False print(is_raining) # False
- Either
- None
- Represents “nothing” or empty:
data = None
- Represents “nothing” or empty:
🔹 Operators
Operators let you perform actions on variables and values.
1. Arithmetic Operators
a = 10
b = 3
print(a + b) # Addition → 13
print(a - b) # Subtraction → 7
print(a * b) # Multiplication → 30
print(a / b) # Division → 3.333...
print(a // b) # Floor division → 3
print(a % b) # Modulus (remainder) → 1
print(a ** b) # Exponent → 1000
2. Comparison Operators
print(a == b) # Equal → False
print(a != b) # Not equal → True
print(a > b) # Greater than → True
3. Logical Operators
x = True
y = False
print(x and y) # False
print(x or y) # True
print(not x) # False
4. Assignment Operators
c = 5
c += 2 # same as c = c + 2
print(c) # 7
📝 Mini Task
Try this small exercise:
# Store your name, age, and height in variables.
# Print them in a single sentence.
name = "Alice"
age = 25
height = 5.6
print("My name is", name, ", I am", age, "years old, and my height is", height, "meters.")
👉 Change the values and re-run to see how variables make your code flexible.
✅ Summary
- Variables are names that store values.
- Data types define what kind of value is stored (numbers, strings, booleans, etc.).
- Operators let you do math, compare values, and combine logic.