Python 寻求帮助dir,help

dir用于列出python对象所有的方法,如下以字符串类str为例:

dir (str)
#结果如下:
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__',
 '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__',
 '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace',
 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

然后可以通过help来查询自己需要使用的方法的具体描述:

help(str.split)
#输出结果如下:
Help on method_descriptor:

split(...)
    S.split([sep [,maxsplit]]) -> list of strings

    Return a list of the words in the string S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string is a separator and empty strings are removed
    from the result.

help其他功能补充:

  1. 查看python所有的modules:help(“modules”)
  2. 单看python所有的modules中包含指定字符串的modules: help(“modules yourstr”)
  3. 查看python中常见的topics: help(“topics”)
  4. 查看python标准库中的module:import os.path + help(“os.path”)
  5. 查看python内置的类型:help(“list”)
  6. 查看python类型的成员方法:help(“str.find”)
  7. 查看python内置函数:help(“open”)

猜你喜欢

转载自blog.csdn.net/u010154685/article/details/54767053