-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_functions.py
More file actions
22 lines (20 loc) · 933 Bytes
/
Copy pathusing_functions.py
File metadata and controls
22 lines (20 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# args and kwargs allow handling function parameters
# we use args for positionl/ordinal arguments and kwargs for keyword arguments
def myFn(*args): # *args will make a tuple containing zero or more arguments passed in
# one-arg outcome
if(len(args)== 1):
return 'one argument: {}'.format(args[0])
# two-arg outcome
if(len(args)== 2):
return 'two arguments: {} {}'.format(args[0], args[1])
# else
return 'more than two arguments: {}'.format(args)
def otherFn(*args, **kwargs): # the keyword arguments will be in a dictionary called kwargs
print(args) # see the tuple
print(kwargs)# see the dict
if __name__ == '__main__':
print( myFn('weeble') )
print( myFn('weeble', 'wooble') )
print( myFn('weeble', True, False, [4,3,2], {'name':'value'}) )
otherFn('a', False, [], k=(1,), n={})
otherFn(n=True, x=4, diddledoo=True, result=myFn('coffee'))