Created
October 5, 2015 23:11
-
-
Save poros/3f5956a35fa56b221fc4 to your computer and use it in GitHub Desktop.
Create APIs with multiple aguments instead of a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def func(msg, numbers): | |
print msg | |
for x in numbers: | |
print x | |
func("My numbers are:", [0, 1, 2]) | |
"My numbers are:" | |
0 | |
1 | |
2 | |
func("My numbers are:", []) | |
"My numbers are:" | |
# USING *ARGS | |
def func(msg, *numbers): | |
print msg | |
for x in numbers: | |
print x | |
func("My numbers are:", 0, 1, 2) | |
"My numbers are:" | |
0 | |
1 | |
2 | |
func("My numbers are:") | |
"My numbers are:" | |
func("My numbers are:", *range(3)) | |
"My numbers are:" | |
0 | |
1 | |
2 | |
# note: beware of infinite generators |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment