Skip to content

Commit 29c6375

Browse files
committed
Add program for arbitrary number of function arguments.
1 parent d21a653 commit 29c6375

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

FunctionIntroduction/src/findprime.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ def optional_arg_func(a, b=None, c=30):
3030
print('a={}'.format(a))
3131
print('b={}'.format(b))
3232
print('c={}'.format(c))
33-
3433

34+
def arbitrary_list_arg_func_1(*args):
35+
print('*args: stands for list of optional arguments')
36+
print('Notice arbitrary arguments are passed as a tuple to the function. Thus, one can use it as a iterator.')
37+
print(args)
38+
39+
def arbitrary_list_arg_func_2(a, b, c, *args):
40+
print('*args: stands for list of optional arguments')
41+
print(a, b, c, args)
42+
3543
def main():
3644
for n in range(1, 20):
3745
isprime(n)
@@ -40,5 +48,9 @@ def main():
4048
optional_arg_func(n) # do not provide optional arguments
4149
print()
4250
optional_arg_func(n, 30, 50) # give optional arguments
51+
print()
52+
arbitrary_list_arg_func_1(1,2,3,4,5)
53+
print()
54+
arbitrary_list_arg_func_2(1, 2, 3, 4,5,6,7)
4355

4456
if __name__ == '__main__': main()

0 commit comments

Comments
 (0)