Created
October 19, 2012 07:14
-
-
Save tmf16/3916678 to your computer and use it in GitHub Desktop.
Pythonでの可変長引数
This file contains 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
# 可変長引数(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