Programming paradigms in Python

In this tutorial, we learn about different programming paradigms that are supported by Python.

There are three programming paradigms that are supported by Python:

  • Procedural programming
  • Object-Oriented Programming
  • Functional programming

Procedural programming

Procedural programming simply contains a series of computational steps, these steps instruct the computer on how to solve a task in logical steps. Procedural programming is best for simple programs but is better is use other programming paradigms for solving complex programs.


  • Best for general-purpose programming.
  • Reusability of the code.
  • It is easy to trace the flow of the program.


  • The data is exposed (security issues).
  • Difficult to solve real-world problems.


def Sum(sample_list):
    total = 0
    for x in sample_list:
        total += x
    return total

list1 = [10, 200, 50, 70]
list2 = [3, 26, 33, 13]




Object-Oriented Programming

Object-Oriented Programming is one of the most popular approaches to solve a programming problem, it is done by creating objects.
An object has two characteristics:-

  • attributes
  • behaviors

For example, an object could represent an employee with attributes such as name, title, experience, etc., with behaviors like working, on-leave, underperformed, etc., The four principles of object-oriented:

  1. encapsulation
  2. abstraction
  3. polymorphism
  4. inheritance


  • It can relate to real-world entities.
  • Code Reusability
  • Data hiding


  • Complex Design
  • Large size
  • Slow Speed


class animal:

    species = "bird"

    def __init__(self, name, age): = name
        self.age = age

parrot = animal("parrot", 10)
sparrow = animal("sparrow", 15)

print("parrot is a {}".format(parrot.__class__.species))
print("sparrow is also a {}".format(sparrow.__class__.species))

print("{} is {} years old".format(, parrot.age))
print("{} is {} years old".format(, sparrow.age))


parrot is a bird
sparrow is also a bird
parrot is 10 years old
sparrow is 15 years old

Functional programming

Functional programming is a programming paradigm in which we use functions as the main building blocks of our program. This paradigm uses the approach of “what to solve” instead of  “how to solve”. The main advantage of this approach is that it is easy to use parallel processing because there is no state to consider. However, it is possible is to maintain state in python hence python is also known as an impure functional language.


  • implementing concurrency becomes efficient
  • simple to understand
  • It uses immutable values, making debugging, and testing easier


  • Writing programs is an overwhelming task
  • reduce the readability of the code
  • reduce performance


#Recursive Function to find sum of a list
def Sum(list, i, Len, sum): 

    if Len <= i: 
        return sum 
    sum += list[i] 

    sum = Sum(list, i + 1, Len, sum) 
    return sum 

sample_list = [10, 20, 30, 40] 
sum = 0
Len = len(sample_list) 
print(Sum(sample_list, 0, Len, sum))




There is another question that which paradigm is best? There isn’t any clear answer to that question, if the program just uses a concrete set of steps then it is recommended to use procedural, if the program has real-world analogy then the answer is OOP. So basically it depends on the program and accordingly you have to select the best approach.

Thank you for reading this tutorial. I hope it helps you.

Leave a Reply

Your email address will not be published. Required fields are marked *