Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29c6375

Browse files
committed
Add program for arbitrary number of function arguments.
1 parentd21a653 commit29c6375

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+
defarbitrary_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+
defarbitrary_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
defmain():
3644
forninrange(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)

[8]ページ先頭

©2009-2025 Movatter.jp