Just Enough Python I: the five fundamentals · Topic 2 Free
Variables and data types
int, float, str, bool, None. Naming variables, converting between types, and f-strings for output.
Everything in Python is built on a few basic types. You cannot skip this step.
Variables
A variable is a name for a value. Python has no declare step. You assign, and it exists.
city = "Vancouver"
salary = 95000
remote = True
Names are lowercase with underscores: salary_usd, job_title, is_remote. This is the Python style guide (PEP 8). Follow it from day one, so your code looks like everyone else’s.
The five types you need
| Type | Example | Used for |
|---|---|---|
int | 42, 95000 | Counts, whole numbers |
float | 3.14, 0.1 | Decimals, money, ratios |
str | "Berlin", 'Berlin' | Text. Single or double quotes, both fine |
bool | True, False | Yes/no flags |
None | None | ”No value yet”. Like NULL in SQL |
Check a type with type():
print(type(42)) # <class 'int'>
print(type("42")) # <class 'str'>
Converting between types
Data arrives as text. From a CSV, from an API, from user input. You convert it before you calculate:
salary_text = "85000"
salary = int(salary_text) # 85000
ratio = float("0.15") # 0.15
label = str(2026) # "2026"
"85000" + 1 is an error. int("85000") + 1 is 85001. Half of beginner bugs are this.
f-strings: how you print
Put an f before the quote, and variables in curly braces:
name = "Anna"
age = 29
print(f"{name} is {age} years old.") # Anna is 29 years old.
print(f"Salary: {salary:,} USD") # Salary: 85,000 USD
print(f"Ratio: {ratio:.1%}") # Ratio: 15.0%
You will use f-strings in every log line and every report. Learn the two formats above: :, for thousands separators, :.1% for percentages.
Arithmetic
10 / 3 # 3.333... division always gives a float
10 // 3 # 3 integer division
10 % 3 # 1 remainder
2 ** 10 # 1024 power
Why None matters in data
A missing salary is not 0. It is None. If you store missing values as zero, your averages lie. Same idea as NULL in SQL.
Practice
Real Python 3 runs in your browser. Solve the tasks, or just experiment.