-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_21 Function Argument in Python
More file actions
84 lines (51 loc) · 1.57 KB
/
Copy pathDay_21 Function Argument in Python
File metadata and controls
84 lines (51 loc) · 1.57 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
# TYPES OF ARGUMENTS:----
# 1. Default Arguments
# 2. Keyword Arguments
# 3. Variable Length Argument
# 4. Required Arguments
def average(a, b): # Default Arguments here are a and b
print('The average is :', (a + b) / 2)
average(50, 60)
def average(c=10, d=20):
print('\nThe average is :', (c + d) / 2)
average()
average(50, 30)
def average(x=20, y=50):
print(
'\nThe average is :',
(x + y) / 2,
)
average(x=80)
average(y=40)
def name(fname='Kunal', mname='Karan', lname='Omkar'):
print('Hello', fname, mname, lname) #Keyword Arguments
name()
name('Krish')
name('Krishna', 'Tanisha', 'Ruchit') #Keyword Arguments
# Variable length arguments
def average(*numbers): #This '*' converts numbers into tuples
print('\n', type(numbers)) #The type of '*numbers is tuple'
sum = 0
for i in numbers:
sum = sum + i
print('Average is:', sum / len(numbers))
average(4, 6, 10, 0)
# Keyword Aribitary Argumnets (In form of dictionary)
def name(**name): # This '**' makes the function 'name' a dictionary
print(type(name)) #The type is 'dict'
print('\n\nHello', name['fname'], name['mname'], name['lname'])
name(mname='Ironman and', lname='Spider-man', fname='Captian-America,')
def average(*numbers):
sum = 0
for i in numbers:
sum = sum + i
# return sum/len(numbers) #if we not implement this return statement we will get none(type) as output
c = average(40, 60, 80, 20)
print('\n', c)
def average(*numbers):
sum = 0
for i in numbers:
sum = sum + i
return sum / len(numbers)
c = average(40, 60, 80, 20)
print('\n', c)