Python
Python was created by Guido van Rossum and first released in 1991. It is built for readability, and it lets you write a script, a class hierarchy or a functional pipeline in the same file, using the same simple syntax.
Paradigm: Popular Hybrid Languages
What Makes Python Special
- Everything is an object. Numbers, functions, classes and modules are all objects, so you can store them in lists, pass them as arguments and inspect them at run time.
- Functions are first-class.
lambda, closures,map,filter,functools.reduceand decorators support a functional style without leaving the language. - Comprehensions and generators.
[x*x for x in data if x > 0]and lazyyieldgenerators turn loops into declarative expressions. - Indentation is syntax. Blocks are defined by layout, not braces, which forces the structure you see to be the structure the interpreter runs.
- Dynamic typing with optional hints. Types are checked at run time, but annotations such as
price: floatlet tools like mypy check them ahead of time. - Modern additions.
dataclassesremove class boilerplate andmatch(Python 3.10) adds structural pattern matching, an idea from functional languages.
Example: One cart, three styles
from dataclasses import dataclass
from functools import reduce
@dataclass
class Item: # object-oriented: data plus behaviour
name: str
price: float
qty: int = 1
def total(self):
return self.price * self.qty
cart = [Item("pen", 1.5, 4), Item("book", 12.0), Item("bag", 30.0, 2)]
count = 0 # structured: a loop with changing state
for item in cart:
if item.qty > 1:
count += 1
cheap = [i.total() for i in cart if i.price < 20] # functional
grand = reduce(lambda a, b: a + b, map(Item.total, cart), 0)
print(count, cheap, grand) # 2 [6.0, 12.0] 78.0
How It Works
@dataclassgenerates__init__,__repr__and equality forItem, so the class is only its fields and one method.- The
forloop counts items with a quantity above one by changingcount. This is the plain procedural style. - The list comprehension builds the totals of cheap items with no mutation.
reducewithmapfolds all totals into one number. - All three styles use the same
Itemobjects, and none needed a different language or a special mode.
History and Where It Is Used
Python is used for scripting and automation, web back ends (Django, Flask, FastAPI), data science and machine learning (NumPy, pandas, PyTorch), teaching and scientific computing. It is often the first language people learn. Its standard library is large, and PyPI hosts hundreds of thousands of packages. The reference implementation is CPython, and other implementations such as PyPy focus on speed. See also the full Python roadmap on this site.