Python: What does the slash mean in help() output?
What does the
/ mean in Python 3.4's
help output for
range before the closing parenthesis?
>>> help(range) Help on class range in module builtins: class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range object | | Return a virtual sequence of numbers from start to stop by step. | | Methods defined here: | | __contains__(self, key, /) | Return key in self. | | __eq__(self, value, /) | Return self==value. ...
It signifies the end of the positional only parameters, parameters you cannot use as keyword parameters. Such parameters can only be specified in the C API.
It means the
key argument to
__contains__ can only be passed in by position (
range(5).__contains__(3)), not as a keyword argument (
range(5).__contains__(key=3)), something you can do with positional arguments in pure-python functions.
Also see the Argument Clinic documentation:
To mark all parameters as positional-only in Argument Clinic, add a
/on a line by itself after the last parameter, indented the same as the parameter lines.
The syntax has also been defined for possible future inclusion in Python, see PEP 457 - Syntax For Positional-Only Parameters. At the moment the PEP acts as a reservation on the syntax, there are no actual plans to implement it as such.
★ Back to homepage or read more recommendations: