python幫助說明

用的了python寫腳本,也只是理解後ctrl+s,代碼複用。當遇到陌生的模塊的時候,如何查詢,一直是很模糊的概念。今天記錄點,也當時工具筆記了。html

type(var_1)查看var_1變量類型python

help(var_1) ERROR,應該是help(type(var_1)),只能查看類型或者函數的幫助git

>>> a='111'
>>> a
'111'
>>> help(a)
no Python documentation found for '111'

>>> help(type(a))
Help on class str in module __builtin__:

class str(basestring)
 |  str(object='') -> string
 |

-----------------------------


>>> help(split)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'split' is not defined
>>> 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.

dir(var_1) 查看var_1對象全部的方法
關於兩條下劃線的表明什麼意思,參見這篇python下劃線使用注意api

疑問1:只有方法,沒有屬性麼
疑問2:爲何有些加下劃線了,有些並無加上。ssh

>>> dir(a)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__
format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__get
slice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mo
d__', '__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']
>>>
相關文章
相關標籤/搜索