-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_function.py
More file actions
47 lines (35 loc) · 971 Bytes
/
15_function.py
File metadata and controls
47 lines (35 loc) · 971 Bytes
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
#Functions
#declare function
def personalInfo():
print('Name: John Snow')
print('Age: 22 \n')
personalInfo()
#declare function with return
def sum():
result = 0
for x in range(1,11):
result += x
return result
print(sum(), '\n')
#declare function with arguments
def carInfo(brand, year, km):
print('Brand:', brand, '\nYear:', year, '\nKM:', km, '\n')
carInfo('Renault', 2025, 10000)
#declare function with default arguments
def doorState(state = True):
if state:
print('Door is open \n')
else:
print('Door is closed \n')
doorState()
#declare function with key arguments
def printABC(a, b, c):
print('Value A:', a)
print('Value B:', b)
print('Value C:', c, '\n')
printABC(c = 1, a = 2, b = 3)
#declare function with flexible arguments
def printArgs(*args):
for arg in args:
print('Argument:', arg)
printArgs('Hello', True, 33, ['A', 'B'], ('C', 'D'), {"abc", 34, True, 40, "male"})