Python
Python is a high-level, interpreted language that prizes readability and simplicity — code often reads like executable pseudocode. That clarity, plus an enormous library ecosystem, makes it the default choice for data science, machine learning, automation, and a large share of backend development.
Why it exists: Guido van Rossum created Python in the late 1980s to be easy to read and pleasant to use (named after Monty Python, not the snake). It consistently ranks among the top languages in use and is the most common teaching language. Where it fits: Python dominates data/ML and scientific computing and is a strong backend choice; its main trade-off is raw speed (it's interpreted), which matters for CPU-bound work but rarely for the I/O-bound and glue tasks it excels at.
TL;DR
- High-level, dynamically typed, and exceptionally readable.
- Dominant in data science / ML, automation, and backend APIs.
- The GIL limits CPU-bound threading — use multiprocessing or async I/O.
- Use virtual environments, type hints, and pytest for production code.
Quick Example
A comprehension expresses transform-and-filter in one readable line:
Core Concepts
Key terms
- Interpreter — executes Python code; indentation (whitespace) defines blocks, not braces.
- Dynamic & duck typing — variables have no fixed type; objects are defined by behavior.
- List / dict / tuple — ordered-mutable / key-value / ordered-immutable collections.
- Comprehension — concise syntax for building lists/dicts/sets.
- Generator — a function that
yields values lazily, one at a time. - Decorator — a function that wraps and modifies another function's behavior.
- Everything is an object — functions, classes, and modules can all be passed around.
Common acronyms
PEP (Python Enhancement Proposal; PEP 8 = style guide), pip (installer), PyPI (package index), venv (virtual environment), GIL (Global Interpreter Lock), REPL (interactive shell).
What beginners misunderstand
- Indentation is syntax — wrong indentation is a syntax error (4 spaces per PEP 8).
- Mutable default args —
def f(x=[])reuses one list; default toNoneinstead. isvs==— identity vs value equality.- Always Python 3 — Python 2 reached end of life in 2020.
How Python Runs
Python compiles your source to bytecode, then the PVM interprets it. Complexity tends to arise around the GIL, package/environment management, the import system (circular imports), and memory (reference cycles, large datasets).
Implementations
Common Uses
- Entry-level — automation scripts, web scraping, quick Flask/FastAPI backends, Jupyter analysis.
- Production — ML pipelines, backend APIs (Django/Flask/FastAPI), data engineering (Pandas/PySpark), DevOps tooling.
- By industry — finance (quant/risk), healthcare (medical imaging), science (NumPy/SciPy, bioinformatics), media (recommendation, NLP).
- When not to use — CPU-critical work (Rust/Go/C++), native mobile (Swift/Kotlin), browser code (JavaScript), hard-real-time systems.
Tooling & Ecosystem
Python (PSF License) and its ecosystem are overwhelmingly open-source; proprietary layers focus on ML platforms (Databricks, SageMaker, Vertex AI).
Performance & Scaling
- The GIL — CPython runs one thread of bytecode at a time, so threads don't speed up CPU-bound work; use
multiprocessingfor parallel CPU work andasyncio/threads for I/O-bound concurrency. (A no-GIL build is in progress via PEP 703.) - Interpreter overhead — ~10–100× slower than C for raw computation; push hot numeric work into NumPy/polars or native extensions.
- Scaling — stateless services scale horizontally; use Celery/RQ for background jobs and Spark/Dask for distributed data.
Best Practices
- Isolate dependencies with virtual environments (
venv, uv, poetry). - Add type hints and check with
mypy/pyrightin larger codebases. - Test with pytest; follow PEP 8 (auto-format with
ruff/black). - Never
unpickleuntrusted data; use parameterized queries for SQL; keep secrets out of code.
Comparison
See Go and JavaScript.
Common Mistakes
Mutable default arguments
is vs ==
Myths vs reality
FAQ
What is the GIL and does it make Python slow?
The Global Interpreter Lock serializes execution of Python bytecode, so multithreading doesn't help CPU-bound work — but it doesn't affect I/O-bound concurrency (asyncio/threads) or C extensions like NumPy (which release it). For parallel CPU work, use multiprocessing. A no-GIL CPython is in development.
Python 2 or Python 3?
Always Python 3 — Python 2 reached end of life in 2020 and receives no updates.
When should I not use Python?
For CPU-bound, performance-critical work (Rust/Go/C++), hard-real-time systems (GC pauses), browser code (JavaScript), and native mobile apps. Python shines for data/ML, scripting, automation, and I/O-bound backends.
Do I need type hints?
Not to run code, but yes for any sizable or team codebase — they catch bugs, power autocomplete, and document intent. Pair them with mypy or pyright in CI.
CPython, PyPy, or something else?
CPython is the right default. Switch to PyPy for long-running CPU-bound programs that need its JIT speedup (and don't depend on incompatible C extensions). MicroPython targets microcontrollers; Anaconda packages the scientific stack.
Related Topics
- JavaScript — The web counterpart
- Go — When you need concurrency/performance
- Python Error Handling — Exceptions done well
- Backend Development — Django/Flask/FastAPI
- Data Science — Python's stronghold
- Data Engineering — Pandas/PySpark pipelines