Help()函数在编码过程中有助于拯救大脑的记忆.
>>> help(list)
Help on class list in module builtins:
class list(object)
| list() -> new empty list
| list(iterable) -> new list initialized from iterable's items
>>> dir(zip)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
我可以检索有关序列,函数和类的信息.
然而
>>> help(assert)
File "<stdin>", line 1
help(assert)
^
SyntaxError: invalid syntax
我可以在IDIE窗口中获得诸如’assert’之类的保留字的提示吗?
最佳答案 对于
keywords,您需要将它们放在引号中(否则help(关键字)将不是语法正确的语句).
>>> help('assert')
The "assert" statement
**********************
Assert statements are a convenient way to insert debugging assertions
into a program:
...
您可以使用keyword
module来发现Python语法的关键字究竟是什么.