首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何查看python中返回了哪个函数?

在Python中,可以使用内置的inspect模块来查看函数的返回值。具体步骤如下:

  1. 导入inspect模块:import inspect
  2. 定义一个函数,并在函数体内返回一个值。
  3. 使用inspect.getmembers()函数来获取函数的返回值。

以下是一个示例代码:

代码语言:txt
复制
import inspect

def my_function():
    return "Hello, World!"

result = my_function()

print(inspect.getmembers(result))

运行以上代码,将会输出类似以下的结果:

代码语言:txt
复制
[('__add__', <method-wrapper '__add__' of str object at 0x7f9b6a9e1a00>),
 ('__class__', <class 'str'>),
 ('__contains__', <method-wrapper '__contains__' of str object at 0x7f9b6a9e1a00>),
 ('__delattr__', <method-wrapper '__delattr__' of str object at 0x7f9b6a9e1a00>),
 ('__dir__', <built-in method __dir__ of str object at 0x7f9b6a9e1a00>),
 ('__doc__', 'str(object='') -> str\nstr(bytes_or_buffer[, encoding[, errors]]) -> str\n\nCreate a new string object from the given object. If encoding or\nerrors is specified, then the object must expose a data buffer\nthat will be decoded using the given encoding and error handler.\nOtherwise, returns the result of object.__str__() (if defined)\nor repr(object).\nencoding defaults to sys.getdefaultencoding().\nerrors defaults to 'strict'.'),
 ('__eq__', <method-wrapper '__eq__' of str object at 0x7f9b6a9e1a00>),
 ('__format__', <method-wrapper '__format__' of str object at 0x7f9b6a9e1a00>),
 ('__ge__', <method-wrapper '__ge__' of str object at 0x7f9b6a9e1a00>),
 ('__getattribute__', <method-wrapper '__getattribute__' of str object at 0x7f9b6a9e1a00>),
 ('__getitem__', <method-wrapper '__getitem__' of str object at 0x7f9b6a9e1a00>),
 ('__getnewargs__', <built-in method __getnewargs__ of str object at 0x7f9b6a9e1a00>),
 ('__gt__', <method-wrapper '__gt__' of str object at 0x7f9b6a9e1a00>),
 ('__hash__', <method-wrapper '__hash__' of str object at 0x7f9b6a9e1a00>),
 ('__init__', <method-wrapper '__init__' of str object at 0x7f9b6a9e1a00>),
 ('__iter__', <method-wrapper '__iter__' of str object at 0x7f9b6a9e1a00>),
 ('__le__', <method-wrapper '__le__' of str object at 0x7f9b6a9e1a00>),
 ('__len__', <method-wrapper '__len__' of str object at 0x7f9b6a9e1a00>),
 ('__lt__', <method-wrapper '__lt__' of str object at 0x7f9b6a9e1a00>),
 ('__mod__', <method-wrapper '__mod__' of str object at 0x7f9b6a9e1a00>),
 ('__mul__', <method-wrapper '__mul__' of str object at 0x7f9b6a9e1a00>),
 ('__ne__', <method-wrapper '__ne__' of str object at 0x7f9b6a9e1a00>),
 ('__new__', <built-in method __new__ of type object at 0x55d0b8f3f0a0>),
 ('__reduce__', <built-in method __reduce__ of str object at 0x7f9b6a9e1a00>),
 ('__repr__', <method-wrapper '__repr__' of str object at 0x7f9b6a9e1a00>),
 ('__rmod__', <method-wrapper '__rmod__' of str object at 0x7f9b6a9e1a00>),
 ('__rmul__', <method-wrapper '__rmul__' of str object at 0x7f9b6a9e1a00>),
 ('__setattr__', <method-wrapper '__setattr__' of str object at 0x7f9b6a9e1a00>),
 ('__sizeof__', <built-in method __sizeof__ of str object at 0x7f9b6a9e1a00>),
 ('__str__', <method-wrapper '__str__' of str object at 0x7f9b6a9e1a00>),
 ('__subclasshook__', <built-in method __subclasshook__ of type object at 0x55d0b8f3f0a0>),
 ('capitalize', <built-in method capitalize of str object at 0x7f9b6a9e1a00>),
 ('casefold', <built-in method casefold of str object at 0x7f9b6a9e1a00>),
 ('center', <built-in method center of str object at 0x7f9b6a9e1a00>),
 ('count', <built-in method count of str object at 0x7f9b6a9e1a00>),
 ('encode', <built-in method encode of str object at 0x7f9b6a9e1a00>),
 ('endswith', <built-in method endswith of str object at 0x7f9b6a9e1a00>),
 ('expandtabs', <built-in method expandtabs of str object at 0x7f9b6a9e1a00>),
 ('find', <built-in method find of str object at 0x7f9b6a9e1a00>),
 ('format', <built-in method format of str object at 0x7f9b6a9e1a00>),
 ('format_map', <built-in method format_map of str object at 0x7f9b6a9e1a00>),
 ('index', <built-in method index of str object at 0x7f9b6a9e1a00>),
 ('isalnum', <built-in method isalnum of str object at 0x7f9b6a9e1a00>),
 ('isalpha', <built-in method isalpha of str object at 0x7f9b6a9e1a00>),
 ('isascii', <built-in method isascii of str object at 0x7f9b6a9e1a00>),
 ('isdecimal', <built-in method isdecimal of str object at 0x7f9b6a9e1a00>),
 ('isdigit', <built-in method isdigit of str object at 0x7f9b6a9e1a00>),
 ('isidentifier', <built-in method isidentifier of str object at 0x7f9b6a9e1a00>),
 ('islower', <built-in method islower of str object at 0x7f9b6a9e1a00>),
 ('isnumeric', <built-in method isnumeric of str object at 0x7f9b6a9e1a00>),
 ('isprintable', <built-in method isprintable of str object at 0x7f9b6a9e1a00>),
 ('isspace', <built-in method isspace of str object at 0x7f9b6a9e1a00>),
 ('istitle', <built-in method istitle of str object at 0x7f9b6a9e1a00>),
 ('isupper', <built-in method isupper of str object at 0x7f9b6a9e1a00>),
 ('join', <built-in method join of str object at 0x7f9b6a9e1a00>),
 ('ljust', <built-in method ljust of str object at 0x7f9b6a9e1a00>),
 ('lower', <built-in method lower of str object at 0x7f9b6a9e1a00>),
 ('lstrip', <built-in method lstrip of str object at 0x7f9b6a9e1a00>),
 ('maketrans', <built-in method maketrans of type object at 0x55d0b8f3f0a0>),
 ('partition', <built-in method partition of str object at 0x7f9b6a9e1a00>),
 ('replace', <built-in method replace of str object at 0x7f9b6a9e1a00>),
 ('rfind', <built-in method rfind of str object at 0x7f9b6a9e1a00>),
 ('rindex', <built-in method rindex of str object at 0x7f9b6a9e1a00>),
 ('rjust', <built-in method rjust of str object at 0x7f9b6a9e1a00>),
 ('rpartition', <built-in method rpartition of str object at 0x7f9b6a9e1a00>),
 ('rsplit', <built-in method rsplit of str object at 0x7f9b6a9e1a00>),
 ('rstrip', <built-in method rstrip of str object at 0x7f9b6a9e1a00>),
 ('split', <built-in method split of str object at 0x7f9b6a9e1a00>),
 ('splitlines', <built-in method splitlines of str object at 0x7f9b6a9e1a00>),
 ('startswith', <built-in method startswith of str object at 0x7f9b6a9e1a00>),
 ('strip', <built-in method strip of str object at 0x7f9b6a9e1a00>),
 ('swapcase', <built-in method swapcase of str object at 0x7f9b6a9e1a00>),
 ('title', <built-in method title of str object at 0x7f9b6a9e1a00>),
 ('translate', <built-in method translate of str object at 0x7f9b6a9e1a00>),
 ('upper', <built-in method upper of str object at 0x7f9b6a9e1a00>),
 ('zfill', <built-in method zfill of str object at 0x7f9b6a9e1a00>)]

上述结果展示了返回值的各种属性和方法。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券