-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_parameters.py
More file actions
50 lines (36 loc) · 1.31 KB
/
Copy pathfunction_parameters.py
File metadata and controls
50 lines (36 loc) · 1.31 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
'''
From a function's perspective:
A parameter is the variable listed inside the parentheses in the function definition.
An argument is the value that is sent to the function when it is called.
'''
#function with two parameters
def foo1(name1, name2):
print(name1, name2)
#function with three parameters
def foo2(name1, name2, name3):
print(name1, name2, name3)
#function with one parameter, and one default parameter
#non-default arguments cannot appear after default arguments
def foo3(name1, name2='Dragonite'):
print(name1, name2)
#function with non-keyword arguments
#args will be tuple
def foo4(*args):
print(args)
#function with keyword arguments
#kwargs will be dict
def foo5(**kwargs):
print(kwargs)
#call with positional arguments
foo1('Jigglypuff','Dragonite')
#call with keyword arguments
foo2(name2='Ditto', name3='Jigglypuff', name1='Lapras')
#call with mixing positional arguments & keyword arguments
#positional arguments cannot appear after keyword arguments
foo2('Ditto', name3='Lapras', name2='Mew')
#call with only one argument
foo3('Jigglypuff')
#call with arbitrary number of arguments
foo4('Mew', 'Ditto', 'Lapras', ('Plusle','Minun'))
#call with arbitrary number of arguments, each argument's types are key=value
foo5(name1='Mew', name2='Ditto', name3='Lapras', name4='Snorlax')