-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path56_Python_Functions.py
More file actions
115 lines (74 loc) · 1.89 KB
/
56_Python_Functions.py
File metadata and controls
115 lines (74 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Python Functions
print("Python Functions")
# Creating a function
print("\nCreating a function")
def function1():
print("Hi, from a Function!")
# Calling the function
function1()
# Arguments
print("\nArguments")
def function2(name):
print("Hi,", name)
function2("Zaber")
function2("Asif")
function2("Sajal")
# Number of arguments
print("\nNumber of arguments")
def function3(fname, lname):
# print("Hi,", fname, lname)
print("Hi," + " " + fname + " " + lname + "!")
function3('Md', 'Zaber')
function3('Md', 'Muttakin')
# Arbitrary arguments, *args
print("\nArbitrary arguments, *args")
def function4(*players):
print(players)
print("Top player:", players[0])
function4('Zaber', 'Sajal', 'Asif', 'Muttakin')
# Keyword arguments
print("\nKeyword arguments")
def function5(fruit2,fruit1):
print(fruit1, "should be in every list.")
function5(fruit2 = 'Banana', fruit1 = 'Apple')
# Arbitrary keyword arguments, **kwargs
print("\nArbitrary keyword arguments, **kwargs")
def function6(**car):
print(car)
function6(brand='Toyota',color='Blue',year='1993')
function6(brand='Nissan',color='Silver',year='1999')
# Default parameter value
print("\nDefault parameter value")
def function7(country='Bangladesh'):
print("I am from " + country)
function7()
function7("Canada")
function7("Italy")
# Passing a list as an argument
print("\nPassing a list as an argument")
colors = ['red','green','blue']
def function8(color):
# print(color)
for x in color:
print(x)
function8(colors)
# Return values
print("\nReturn values")
def function9(num):
return num * 3
print(function9(3))
print(function9(5))
print(function9(9))
print(function9(9)+function9(1))
# The pass statement
print("\nThe pass statement")
def function10():
pass
function10() # Error will not occur
# Recursion
print("\nRecursion")
def try_recursion(k):
print(k)
if k > 0:
try_recursion(k-1)
try_recursion(3)