1
1
"""
2
- A pure Python implementation of Functions
2
+ A pure Python implementation of Functions
3
3
4
4
A Function in python is a reusable piece of code that takes N parameters and can be called as many times as we want.
5
5
Functions are important because:
10
10
11
11
"""
12
12
13
- def addition (a ,b ):
13
+
14
+ def addition (a , b ):
14
15
"""
15
16
A function in python is created with a keyword 'def' in all small , followed with the name of the function for example in here addition
16
- and in the brackets we pass on the parameter's value the function will work upon
17
+ and in the brackets we pass on the parameter's value the function will work upon
17
18
18
19
"""
19
20
return a + b
@@ -23,11 +24,12 @@ def addition(a ,b):
23
24
24
25
"""
25
26
26
- print (addition (4 ,5 ))
27
+
28
+ print (addition (4 , 5 ))
27
29
28
30
"""
29
31
To call a function you type in the function's name and pass on the values that you want your function to pass
30
- For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5
32
+ For example : Result for this case will be 9 as 4 + 5 here automatically the function assumes a = 4 and b = 5
31
33
another way to call a function is to specify the values for example print(addition(a=4 ,b= 5))
32
34
33
35
"""
@@ -40,13 +42,16 @@ def addition(a ,b):
40
42
41
43
"""
42
44
45
+
43
46
def each_item_in_list (list ):
44
47
for item in list :
45
48
print (item )
46
49
"""
47
50
Here the function takes takes the parameter 'list' and this function when called upon will print every item of the list
48
51
"""
49
- each_item_in_list ([1 ,2 ,3 ,4 ,5 ,6 ])
52
+
53
+
54
+ each_item_in_list ([1 , 2 , 3 , 4 , 5 , 6 ])
50
55
51
56
"""
52
57
Upon calling the function the result will be
0 commit comments