Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 5, 2015 23:11
Show Gist options
  • Save poros/3f5956a35fa56b221fc4 to your computer and use it in GitHub Desktop.
Save poros/3f5956a35fa56b221fc4 to your computer and use it in GitHub Desktop.
Create APIs with multiple aguments instead of a list
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