Programming Paradigms in Python
Programming Paradigms in Python
Disadvantages
Data protection
Not suitable for all types of problems
Slow Speed
Example:
class Emp:
self.name = name
self.age = age
def info(self):
# made here
Emp("Hilbert", 16),
Emp("Alice", 30)]
# used here
emp.info()
Output:
Hello, John. You are 43 old.
Hello, Hilbert. You are 16 old.
Hello, Alice. You are 30 old.
# of a list
# modularization is done by
# functional approach
def sum_the_list(mylist):
res = 0
res += val
return res
print(sum_the_list(mylist))
Output:
100
import functools
def sum_the_list(mylist):
if len(mylist) == 1:
return mylist[0]
else:
print(functools.reduce(lambda x, y: x + y, mylist))
Output:
110