Why I Cannot Use Keyword Argument On Range Function?
Solution 1:
range()
is not a python function. It is a C type; C types follow different rules for arguments and range()
only accepts positional arguments.
See the Calls expressions documentation:
CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. In CPython, this is the case for functions implemented in C that use
PyArg_ParseTuple()
to parse their arguments.
The positional parameters of range()
are not named so cannot be used as keyword arguments.
Solution 2:
As you know by now the real answer is that range
is a C function which for some reason does not have the same rules of python (would be nice to know why).
But you can do this instead:
range(*{'start':0,'stop':10,'step':2}.values())
Post a Comment for "Why I Cannot Use Keyword Argument On Range Function?"