Python Basics — Core Concepts
Python: Designed to Be Read
Python was created by Guido van Rossum, a Dutch programmer who released it in 1991. His design philosophy was unusual: code should be readable first, executable second. Programs are read far more often than they’re written, so clarity matters.
He codified this in “The Zen of Python” — a set of 19 aphorisms you can read anytime by typing import this in Python. The most quoted one: Readability counts.
That philosophy shapes everything about the language.
How Python Runs Your Code
Python is an interpreted language. When you run a Python script, an interpreter reads your code line by line and executes it on the fly. This is different from compiled languages like C++, where code is converted to machine instructions once before running.
What this means in practice:
- Slower — interpretation at runtime adds overhead (usually 10-100x slower than C)
- Faster to write — no compile step, no type declarations, just run
- Easier to debug — errors show you the exact line that failed
For most applications — web apps, data analysis, automation scripts — this tradeoff is worth it. When speed is critical, Python code can call into C libraries (NumPy does this, which is why number-crunching in Python can be fast despite the interpreter overhead).
The Basic Building Blocks
Statements and Expressions
A statement is a complete instruction. A expression produces a value.
# Statement: assigns a value
name = "Alice"
# Expression: produces a value (but here we print it)
print(name.upper()) # → ALICE
Python executes statements in order, top to bottom, unless you use control flow (loops, conditionals) to change that.
Indentation as Syntax
Python uses indentation to define code blocks. This is the feature that surprises most newcomers:
if temperature > 30:
print("Hot day")
print("Stay hydrated")
print("This always runs")
The two lines indented under if only run when the condition is true. The last line always runs because it’s at the same level as the if.
Most languages use curly braces {} for this. Python’s choice of indentation is controversial but has a real upside: all Python code is formatted consistently. You can read any Python file and know exactly what’s inside what.
Comments
Lines starting with # are comments — ignored by Python, read by humans:
# Calculate the total price with tax
total = price * 1.20 # 20% VAT in the UK
Good comments explain why, not what. The code already shows what it does.
The Python Standard Library
Python ships with an enormous built-in library — the “batteries included” philosophy. You can send HTTP requests, parse CSV files, generate random numbers, work with dates, compress files, and thousands of other things without installing anything extra.
import datetime
today = datetime.date.today()
print(today) # → 2026-03-27
The import statement loads a module (a collection of related functions). Python has thousands of built-in modules and hundreds of thousands of third-party ones on PyPI (the Python Package Index).
Running Python
Two main ways:
Interactive mode — type python3 in a terminal, get a prompt where each line runs immediately. Good for experimenting.
Script mode — write code in a .py file, run it with python3 myfile.py. Good for anything real.
Most serious development uses an IDE (VS Code with the Python extension is the most popular), which gives you syntax highlighting, error hints, and a built-in terminal.
Common Misconception: Python Is Only for Beginners
Python is beginner-friendly, but it’s not a beginner language. It’s the dominant language in:
- Machine learning — PyTorch, TensorFlow, scikit-learn are all Python
- Data science — pandas, NumPy, Jupyter are standard tools
- Web development — Django and FastAPI power major production systems
- Automation — the default scripting language for most DevOps tools
The tradeoff: Python is slower than compiled languages and uses more memory. For applications where raw performance is critical (game engines, operating systems, embedded systems), other languages are better. For everything else, Python’s productivity advantages usually win.
One Thing to Remember
Python runs code top to bottom, uses indentation to define structure, and ships with thousands of built-in tools — which is why you can build real things without learning much boilerplate first.
See Also
- Python Async Await Async/await helps one Python program juggle many waiting jobs at once, like a chef who keeps multiple pots moving without standing still.
- Python Booleans Make Booleans click with one clear analogy you can reuse whenever Python feels confusing.
- Python Break Continue Make Break Continue click with one clear analogy you can reuse whenever Python feels confusing.
- Python Closures See how Python functions can remember private information, even after the outer function has already finished.
- Python Comprehensions See how Python lets you build new lists, sets, and mini lookups in one clean line instead of messy loops.