-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path11_functions.py
More file actions
81 lines (62 loc) · 1.45 KB
/
11_functions.py
File metadata and controls
81 lines (62 loc) · 1.45 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
# def sample_func():
# print("This is a sample function")
# # Call the function
# sample_func()
# def add(num_1, num_2):
# """
# This function performs addition of 2 numbers
# """
# res = num_1 + num_2
# return res
# # Call the function
# # res = add(1, 2)
# res = add(num_2=1, num_1=2)
# print(res)
# help(add)
# def add(num_1, num_2, num_3=10):
# """
# This function performs addition of 2 numbers
# """
# res = num_1 + num_2 + num_3
# return res
# Call the function
# res = add(1, 2)
# res = add(num_2=1, num_1=2)
# print(res)
# One user enters 10 numbers and another user enters 100 numbers. Define your function to handle this situation
# A: Variable length arguments
# def add(*nums):
# """
# This function performs addition of 2 numbers
# """
# res = sum(nums)
# return res
# res = add(1, 2, 4)
# print(res)
# res = add(1, 2, 4, 5, 6)
# print(res)
# def add(num1, num2, *args):
# """
# This function performs addition of 2 numbers
# """
# res = num1 + num2 + sum(args)
# return res
# res = add(1, 2, 4, 5)
# print(res)
# res = add(1, 2, 4, 5, 6)
# print(res)
def add(*args, **kwargs):
"""
This function performs addition of 2 numbers
"""
print(args, kwargs)
res = add(1, 2, 4)
print(res)
res = add(1, 2, 4, num1=5, num2=6)
print(res)
# map
# filter
# Lambda: inline function
add_numbers = lambda num1, num2: num1 + num2
res = add_numbers(1, 2)
print(res)