Professional Documents
Culture Documents
Programming Paradigms: Using Python
Programming Paradigms: Using Python
Programming Paradigms: Using Python
Paradigms
Using Python
Programming Paradigms
• [ 1, 2, 3, 4, 5 ]
Ans:
• [1, 4, 9, 16, 25 ]
Imperative
temp_list = [ 1, 2, 3, 4, 5]
result_list = [ ]
result_list.append ( item ** 2 )
——————————————————-
result_list = [ 1, 4, 9, 16, 25 ]
Procedural
temp_list = [ 1, 2, 3, 4, 5]
result_list = [ ]
result_list.append ( item ** 2 )
return result_list
——————————————————-
result_list = [ 1, 4, 9, 16, 25 ]
Object Oriented
class ChangeList(object):
self.any_list = any_list
def do_square(self):
self.square = [ ]
for x in any_list:
square.append( x**2)
temp_list_object = ChangeList(my_list)
temp_list_object.do_square( )
print(temp_list_object.square)
——————————————————-
[ 1, 4, 9, 16, 25 ]
Functional
import functools
temp_list = [1, 2, 3, 4, 5]
print (result_list)
——————————————————-
[ 1, 4, 9, 16, 25 ]
Functions and Functional
Paradigms
for x in l:
function_name(x)
map ( function_name, l )