Python informer

Improve your Python coding skills

Python programming paradigms

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.