Skip to content

Instantly share code, notes, and snippets.

@tmf16
Created October 19, 2012 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmf16/3916678 to your computer and use it in GitHub Desktop.
Save tmf16/3916678 to your computer and use it in GitHub Desktop.
Pythonでの可変長引数
# 可変長引数(tuple)
>>> def func(*v):
... print v
...
>>> func(1)
(1,)
>>> func(1, "ABC", True)
(1, 'ABC', True)
# 可変長引数(dict)
>>> def func(**v):
... print v
...
>>> func(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: func() takes exactly 0 arguments (1 given)
>>> func(a=1)
{'a': 1}
>>> func(a=1, b="ABC", c=True)
{'a': 1, 'c': True, 'b': 'ABC'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment