Python is the most-used programming language in data analysis, scientific computing, machine learning, and (increasingly) economics. The reasons are unflashy: it's readable, the standard library is generous, and the third-party ecosystem — pandas, NumPy, statsmodels, matplotlib — covers virtually every analysis task an economist will ever need to do.
The interactive REPL
Python is interactive: you type an expression and the interpreter prints its value. In a script, you must use print() to display output. In a notebook (Jupyter, this practice page), the last expression in a cell is automatically displayed. This dual behaviour is the source of one in three beginner bugs — an expression that prints in a notebook but disappears silently in a script.
>>> 2 + 35>>> name = 'Kenya'>>> name'Kenya'>>> print(name)Kenya
The five built-in types you'll touch in your first hour
- int — whole numbers, arbitrary precision (Python ints don't overflow)
- float — IEEE 754 double-precision floating point
- str — text, immutable, single or double quotes both work
- bool — True or False, capitalised
- None — the explicit absence of a value
Variables are names, not boxes
x = 5 does not declare a variable of type int. It binds the name x to the integer object 5. Reassigning x = 'hello' is fine — x is now bound to a string. Python is dynamically typed: types belong to values, not to variables. This flexibility is the language's superpower and its biggest source of bugs (a typo silently creates a new variable). Modern practice uses type hints (covered in module 13) to recover some safety.
Why Python won the data race
R was the academic statistics language. SAS and Stata were the regulated-industry languages. Python won not because it was best at any one thing, but because it was good enough at everything — analysis, web scraping, automation, machine learning — that an analyst could stay in one language for an entire pipeline. The 2010s decade-long compounding of pandas, scikit-learn, TensorFlow, and Jupyter sealed the deal.
Run Python in your browser
The practice environment to the right of this course runs real CPython 3.12 compiled to WebAssembly via Pyodide. Pandas, NumPy, and matplotlib are pre-loaded. Three Kenyan datasets are pre-defined as DataFrames. Every exercise runs against real data.
Exercise
Print the string 'Hello, Kenya' (exact text, including the comma).