用的了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'] >>>