python中查看对象的属性和方法以及如何使用
.dir()查看对象有什么,help()查看怎么用
Python有众多内置函数,记不住有什么,记不住功能.It’s easy to solve
dir()
带参数时,返回参数的属性、方法列表
help()
函数查看函数或模块用途的详细说明
因此先查看有什么再查看如何用
例子
D = [A,B,C]
#print(D)
dir(D)#等价与dir([ ])
help(D.pop)
dir(D)
或者dir([ ])
将返回如下列表
[‘add’,
‘class’,
‘contains’,
‘delattr’,
‘delitem’,
‘dir’,
‘doc’,
‘eq’,
‘format’,
‘ge’,
‘getattribute’,
‘getitem’,
‘gt’,
‘hash’,
‘iadd’,
‘imul’,
‘init’,
‘init_subclass’,
‘iter’,
‘le’,
‘len’,
‘lt’,
‘mul’,
‘ne’,
‘new’,
‘reduce’,
‘reduce_ex’,
‘repr’,
‘reversed’,
‘rmul’,
‘setattr’,
‘setitem’,
‘sizeof’,
‘str’,
‘subclasshook’,
‘append’,
‘clear’,
‘copy’,
‘count’,
‘extend’,
‘index’,
‘insert’,
‘pop’,
‘remove’,
‘reverse’,
‘sort’]
其中有列表方法pop
,使用help(D.pop)
得到使用帮助
Help on built-in function pop:
pop(index=-1, /) method of builtins.list instance
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.