在Python中,可以使用inspect
模块来查看函数的参数。以下是一个示例代码:
import inspect
def my_func(a, b, c=1, *args, **kwargs):
pass
argspec = inspect.getfullargspec(my_func)
print("Positional arguments:", argspec.args)
print("Keyword-only arguments:", argspec.kwonlyargs)
print("Default values:", argspec.defaults)
print("Variable positional arguments (*args):", argspec.varargs)
print("Variable keyword arguments (**kwargs):", argspec.varkw)
在这个示例中,getfullargspec
函数将返回一个FullArgSpec
对象,其中包含了函数my_func
的参数信息。您可以访问这个对象的属性来查看函数的参数类型、默认值、可变参数等信息。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python怎么遍历函数的参数