Skip to main content
 首页 » 编程设计

python 检查模块 positional_only 参数

2025年04月02日15落叶无声

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.

有人可以给我一个 positional_only 参数的例子吗?

请您参考如下方法:

>>> 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. 

此处 str.split 有一个仅位置参数的示例:

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