-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathprog24_args_kwargs.py
More file actions
43 lines (32 loc) · 962 Bytes
/
prog24_args_kwargs.py
File metadata and controls
43 lines (32 loc) · 962 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
# *args and **kwards keywords. it is a way to pass the agruments
# args and kwargs pass the arguments as a tuple
"""
how to pass args , kwargs and one normal arguments together:
Pass first normal argements then *args then **kwargs, for example:
def myfunction(id, *args, **kwargs):
pass
"""
def myfunc(a,b,c,d):
print(a,b,c,d)
myfunc("rmz", "asw", "vvm", "awj")
# ----- *args Example-1-----------
print("----*args Example-1----:")
def myfunc1(*args):
print(type(args))
print(*args)
mylist = ["rmz", "asw", "vvm", "awj", "bav"]
myfunc1(*mylist)
# ----- *args Example-2-----------
print("----*args Example-2----:")
def myfunc2(*args):
for item in args:
print(item)
myfunc2(*mylist)
# ----- *args Example-3-----------
print("----*args Example-3----:")
def myfunc3(a, *args):
print(a)
for item in args:
print(item)
a = "This is employee code."
myfunc3(a, *mylist)