@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2503 / 12833)
There are the following two arguments.
https://docs.python.jp/3/glossary.html
Positional argument Actual argument Please refer to.
...
keyword argument Actual argument Please refer to.
...
You can mix positional and keyword arguments.
http://ideone.com/bfvZTn
def check_inputs(name1, value1, name2, value2):
print('%s: %s' % (name1, value1))
print('%s: %s' % (name2, value2))
# mixing of [keyword] and [positional] arguments
check_inputs(value1=3.1415, name1="pi", "napier", 2.718)
result
Compilation error time: 0 memory: 23288 signal:0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/py_compile.py", line 117, in compile
raise py_exc
py_compile.PyCompileError: File "prog.py", line 6
check_inputs(value1=3.1415, name1="pi", "napier", 2.718)
SyntaxError: non-keyword arg after keyword arg
Positional argument is not good after keyword argument.
http://ideone.com/Kcwf5Q
def check_inputs(name1, value1, name2, value2):
print('%s: %s' % (name1, value1))
print('%s: %s' % (name2, value2))
# mixing of [positional] and [keyword] arguments
check_inputs("pi", 3.1415, value2=2.718, name2="napier")
result
Success time: 0 memory: 23288 signal:0
pi: 3.1415
napier: 2.718
Why shouldn't it be a keyword argument or a positional argument?
I think it's difficult to tell which index argument is after the positional argument.
If there is a positional argument first, it is determined sequentially from 0 of the index, and if it becomes a keyword argument in the middle, it is possible to process the keyword argument from there.
I personally don't want to use it (as of March 29, 2017). I feel that the source is hard to read because it is inconsistent.
If you can use it well, you may use it.
@ shiracamus's Comment taught me how to use the mix of positional arguments / keyword arguments.
Thank you for the information.
Recommended Posts