Python:函数文档
是否有一种方法可以检查python内部的函数或方法做了什么,类似于Matlab中的帮助函数。我想在不必搜索的情况下获得函数的定义。是的,您可以在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
帮助(无论什么)
>>> 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
然后,如果您需要查找有关模块的信息,请加载该模块并键入dir(module_name)以查看模块中定义的方法。感谢您快速而全面的回答。弦的东西很有用,我不知道为什么我没有试过。同样在玩过之后,我发现你必须键入
help('module.method')
才能获得方法的帮助,因此对于sqrthelp('math.sqrt')
和append,它是help('list.append')
我读了150页的python书籍,但它从来没有提到dir()或help(),这让我感到惊讶。谢谢