python: how to get information about a function?

后端 未结 4 1695
北荒
北荒 2020-11-29 03:50

When information about a type is needed you can use:

my_list = []
dir(my_list)

gets:

[\'__add__\', \'__class__\', \'__conta         


        
相关标签:
4条回答
  • 2020-11-29 04:17

    Try

    help(my_list)
    

    to get built-in help messages.

    0 讨论(0)
  • 2020-11-29 04:25

    Or

    help(list.append)
    

    if you're generally poking around.

    0 讨论(0)
  • 2020-11-29 04:26

    You can use pydoc.

    Open your terminal and type python -m pydoc list.append

    The advantage of pydoc over help() is that you do not have to import a module to look at its help text. For instance python -m pydoc random.randint.

    Also you can start an HTTP server to interactively browse documentation by typing python -m pydoc -b (python 3)

    For more information python -m pydoc

    0 讨论(0)
  • 2020-11-29 04:29

    In python: help(my_list.append) for example, will give you the docstring of the function.

    >>> my_list = []
    >>> help(my_list.append)
    
        Help on built-in function append:
    
        append(...)
            L.append(object) -- append object to end
    
    0 讨论(0)
提交回复
热议问题