Junior — Middle
Is Python a programming language based on functional principles or object-oriented paradigm?
sobes.tech AI
Answer from AI
Python is a multi-paradigm programming language that supports both object-oriented programming (OOP) and functional principles. In Python, you can create classes and objects, use inheritance and encapsulation, as well as apply higher-order functions, lambda expressions, generators, and other functional constructs.
Example of using OOP and functional elements in Python:
class Calculator:
def __init__(self, value):
self.value = value
def apply(self, func):
self.value = func(self.value)
calc = Calculator(10)
calc.apply(lambda x: x * 2) # functional style
print(calc.value) # 20
Thus, Python is not limited to a single paradigm and allows the use of the approach most suitable for the task.