Python programming paradigms

Martin McBride, 2018-04-05

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.

Tag cloud

2d arrays abstract data type alignment and array arrays bezier curve built-in function close closure colour comparison operator comprehension context conversion data types design pattern device space dictionary duck typing efficiency encryption enumerate filter font font style for loop function function composition function plot functools generator gif gradient greyscale higher order function html image processing imagesurface immutable object index inner function input installing iter iterator itertools lambda function len linspace list list comprehension logical operator lru_cache mandelbrot map monad mutability named parameter numeric python numpy object open operator optional parameter or partial application path positional parameter print pure function radial gradient range recipes recursion reduce rgb rotation scaling sequence slice slicing sound spirograph str stream string subpath symmetric encryption template text text metrics transform translation transparency tuple unpacking user space vectorisation webserver website while loop zip

Copyright (c) Axlesoft Ltd 2020