-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9. function.py
52 lines (41 loc) · 1.22 KB
/
9. function.py
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
#function-allow us to reuse our code without repeating ourselves
#pass keyword
def hello_func():
pass#it says that we dont want a parameter rn but will pass later
print(hello_func())
def hello_func():
print('hello')
hello_func()
#executing function
#function reusablity
def hello_func():
print('hello')
hello_func()
hello_func()
hello_func()
hello_func()
hello_func()
#return
def hello_func():
return 'hello'#stores value in function
hello_func()#no output
#but if we print our function then it will give us output
print(hello_func().upper())
def hello_func(greeting):
return '{} Function'.format(greeting)
print(hello_func('Hi'))
def hello_func(greeting, name='you'):
return '{}, {} shutup'.format(greeting,name)
print(hello_func('Hey'))
def hello_func(greeting, name='you'):
return '{}, {} shutup'.format(greeting,name)
print(hello_func('Hey', name='tanishka'))
#positional keyword arguments
#
def student_info(*args, **kwargs):#accepting an arbitrary number
print(args)#tuple with positional arguments
print(kwargs)#dictionary with keyword values
student_info('maths', 'art', name = 'tanishka', age = 19)
courses = ['maths', 'art']
info = {'name': 'tanishka', 'age': '19'}
student_info(*courses,**info)#unpacks the value