demalegabi
demalegabi

Reputation: 607

python inspect module positional_only param

Value must be supplied as a positional argument.

Python has no explicit syntax for defining positional-only parameters, but many built-in and extension module functions (especially those that accept only one or two parameters) accept them.

Can someone give me an example of a positional_only argument?

Upvotes: 2

Views: 77

Answers (1)

wim
wim

Reputation: 362557

>>> print str.split.__doc__
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.

Here str.split has an example of a positional only argument:

>>> s = 'hello world'
>>> s.split(' ', maxsplit=1)
TypeError: split() takes no keyword arguments
>>> s.split(' ', 1)
['hello', 'world']

Upvotes: 1

Related Questions