2012年6月9日

python 物件型态取得使用方法协助-help 指令


python 物件型态取得使用方法协助-help 指令
当你对python物件使用上有不清楚或想知道更多使用方法时,可利用dir或help的指令直接对已指定值的变数或方法套上这两个指令即可。
dir函式只是给出可使用的方法或属性名称,要详细了解这个方法或名称如何使用,就必须用help的函式了。


>>> S'Hello'>>> dir(S)['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode','encode', 'endswith', 'expandtabs', 'find', '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(S.split)Help on built-in function split:
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.
>>>
利用help函式,会显示这个方法或函式的语法与说明。

没有评论:

发表评论

BlogAD