Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:函数文档_Python - Fatal编程技术网

Python:函数文档

Python:函数文档,python,Python,是否有一种方法可以检查python内部的函数或方法做了什么,类似于Matlab中的帮助函数。我想在不必搜索的情况下获得函数的定义。是的,您可以在python交互式解释器中调用帮助(无论什么) >>> help Type help() for interactive help, or help(object) for help about object. >>> help(zip) Help on built-in function zip in module

是否有一种方法可以检查python内部的函数或方法做了什么,类似于Matlab中的帮助函数。我想在不必搜索的情况下获得函数的定义。

是的,您可以在python交互式解释器中调用
帮助(无论什么)

>>> help
Type help() for interactive help, or help(object) for help about object.

>>> help(zip)
Help on built-in function zip in module __builtin__:

zip(...)
    zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]

    Return a list of tuples, where each tuple contains the i-th element
    from each of the argument sequences.  The returned list is truncated
    in length to the length of the shortest argument sequence.
您甚至可以传递(引用)关键字并获得非常详细的帮助:

>>> help('if')
The ``if`` statement
********************

The ``if`` statement is used for conditional execution:

   if_stmt ::= "if" expression ":" suite
               ( "elif" expression ":" suite )*
               ["else" ":" suite]

It selects exactly one of the suites by evaluating the expressions one
by one until one is found to be true (see section *Boolean operations*
for the definition of true and false); then that suite is executed
(and no other part of the ``if`` statement is executed or evaluated).
If all expressions are false, the suite of the ``else`` clause, if
present, is executed.

Related help topics: TRUTHVALUE

>>> help('def')
Function definitions
********************

A function definition defines a user-defined function object
....
甚至是一般性的话题:

>>> help('FUNCTIONS')
Functions
*********

Function objects are created by function definitions.  The only
operation on a function object is to call it: ``func(argument-list)``.

There are really two flavors of function objects: built-in functions
and user-defined functions.  Both support the same operation (to call
the function), but the implementation is different, hence the
different object types.

See *Function definitions* for more information.

Related help topics: def, TYPES

调用内置的帮助系统。(此功能用于交互式使用。)如果未给出任何参数,则交互式帮助系统将在口译员控制台上启动

如果参数是字符串,则该字符串将作为模块、函数、类、方法、关键字或文档主题的名称进行查找,并在控制台上打印帮助页面

如果参数是任何其他类型的对象,则会生成该对象的帮助页

help()函数为您提供几乎所有方面的帮助,但如果您搜索某个内容(如要使用的模块),则键入help('modules'),它将搜索可用的模块


然后,如果您需要查找有关模块的信息,请加载该模块并键入dir(module_name)以查看模块中定义的方法。

感谢您快速而全面的回答。弦的东西很有用,我不知道为什么我没有试过。同样在玩过之后,我发现你必须键入
help('module.method')
才能获得方法的帮助,因此对于sqrt
help('math.sqrt')
和append,它是
help('list.append')
我读了150页的python书籍,但它从来没有提到dir()或help(),这让我感到惊讶。谢谢