Sobes.tech
Junior — Middle

Can you list the main programming paradigms used in Python?

sobes.tech AI

Answer from AI

Python supports several main programming paradigms, making it a versatile language:

  • Imperative programming — sequential execution of instructions, changing the program state.
  • Object-oriented programming (OOP) — using classes and objects to model data and behavior.
  • Functional programming — using functions as first-class objects, supporting higher-order functions, lambda expressions, immutable data structures.
  • Procedural programming — organizing code into procedures or functions.

An example of combining OOP and functional style:

class Calculator:
    def __init__(self, initial=0):
        self.value = initial

    def add(self, x):
        self.value += x
        return self

    def apply(self, func):
        self.value = func(self.value)
        return self

calc = Calculator()
result = calc.add(5).apply(lambda x: x * 2).value  # result = 10

Thus, Python flexibly allows using different programming styles depending on the task.