A programming paradigm is a particular style or approach to programming. Different programming languages support different paradigms. Python supports 3 main programming paradigms:
- Procedural programming - this is type of programming you might use when you are first learning Python. A program might consist of a sequence of lines assignment statements, if statements, and loops. Larger programs might define functions to make the code more intelligible and maintainable. This style of coding is fine for scripts and simple programs, but more complex programs usually benefit from an alternative style. Older languages such as C are procedural only, but many languages (including Python) support procedural programming alongside other styles.
- Object oriented programming (OOP) - here we organise our code into objects. An object is a set of data items that can exchange messages with other objects (often this message passing is done by calling functions on the object). Every object has a particular type, or class, that defines the data and methods it has. Python supports object oriented programming.
- Functional programming - in this style, we use functions as the main building blocks of our program. This is different from procedural programming, where we might use functions to structure our code. In functional programming, functions are first class objects, so we can create functions that operate on functions (called higher order functions).
In Python it is easy to mix these paradigms together, using each one as appropriate for a particular task.
There are other paradigms that Python does not directly support, in particular:
- Declarative programming - this style of programming works by defining what the program should do but not how it should do it. An example is SQL - it allows you to query a database for particular records without specifying exactly how the database should be searched. Python does not support declarative programming.
Join the PythonInformer Newsletter
Sign up using this form to receive an email when new content is added:
2d arrays abstract data type alignment and angle animation arc array arrays bar chart bar style behavioural pattern bezier curve built-in function callable object chain circle classes clipping close closure cmyk colour combinations comparison operator comprehension context context manager conversion count creational pattern data science data types decorator design pattern device space dictionary drawing duck typing efficiency ellipse else encryption enumerate fill filter font font style for loop formula function function composition function plot functools game development generativepy tutorial generator geometry gif global variable gradient greyscale higher order function hsl html image image processing imagesurface immutable object in operator index inner function input installing iter iterable iterator itertools join l system lambda function len lerp line line plot line style linear gradient linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map marker style matplotlib monad mutability named parameter numeric python numpy object open operator optimisation optional parameter or pandas partial application path pattern permutations pie chart pil pillow polygon pong positional parameter print product programming paradigms programming techniques pure function python standard library radial gradient range recipes rectangle recursion reduce regular polygon repeat rgb rotation roundrect scaling scatter plot scipy sector segment sequence setup shape singleton slice slicing sound spirograph sprite square str stream string stroke structural pattern subpath symmetric encryption template text text metrics tinkerbell fractal transform translation transparency triangle truthy value tuple turtle unpacking user space vectorisation webserver website while loop zip zip_longest