gpt4 book ai didi

python 检查模块 positional_only 参数

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:25 26 4
gpt4 key购买 nike

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

关于python 检查模块 positional_only 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37072792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com