Python 可用的**KWARG列表
在python帮助文档中,我经常看到带有函数名和命名参数的签名行,然后您将看到**kwarg(关键字参数) 它将打印到帮助文档字符串:Python 可用的**KWARG列表,python,Python,在python帮助文档中,我经常看到带有函数名和命名参数的签名行,然后您将看到**kwarg(关键字参数) 它将打印到帮助文档字符串: Init signature: list(self, /, *args, **kwargs) Docstring: list() -> new empty list list(iterable) -> new list initialized from iterable's items Type: type 有没有办法
Init signature: list(self, /, *args, **kwargs)
Docstring:
list() -> new empty list
list(iterable) -> new list initialized from iterable's items
Type: type
有没有办法列出可以传递的可用关键字和/或参数 有一个模块,可以帮助您:
>>> inspect.getargspec(aMethod)
(['arg1', 'arg2'], None, None, None)
对于内置方法,您可以使用\uuuu doc\uuu
参数:
>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"
Nope-
*args
和**kwargs
是捕获所有参数,前者将捕获列表中的每个额外未命名参数,后者将捕获dict
中的每个命名参数
使用这些特殊捕获参数中的一个或两个来编写函数/方法的人会决定如何使用它们,除非您查看他们的代码,如果他们没有提供函数/方法的文档,您就无法知道他们的意图或期望得到什么
>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"