Professional Documents
Culture Documents
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 )
Statically Typed Language
• a = 5
• a = “5”
Statically Typed Language
• a = 5
• a = “5”
Dynamically Typed
Language
• a = 5
• a = “5”
Weakly Typed Language
• a = 5
• b = “5”
• c = concatenate(a, b)
• d = add(a, b)
Strongly Typed Language
• a = 5
• b = “5”
• c = concatenate(str(a), b)
• d = add(a, int(b))
Which one is slowest &
Why?
Quiz
1 True or False
• We can pass statements as arguments in imperative
programming language.
pass
one = Point( )
one.x = 3, one.y = 4
two = Point( )
two.x = 3, two.y = 4 one == two
one == two
4. True or False
import copy
c = Circle( )
d = copy.copy ( c )
c == d
5. True or False
import copy
c = Circle( )
d = copy.copy ( c )
c.center == d.center
6. Short Answer (one short
sentence)
•
9. Short Answer (one word/
phrase)
• a = 5, 6.4, “hello”
• type ( a )
10. Short Answer
• Duck