2016-05-06 67 views
2

值必须作为位置参数提供。python检查模块positions_only参数

Python没有明确的定义位置参数的语法,但许多内置和扩展模块函数(特别是那些只接受一个或两个参数的函数)接受它们。

有人能给我一个positions_only参数的例子吗?

回答

1
>>> 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']