dir()
如果对 dir() 的用法不是很清楚,可以使用 help() 来查看帮助:
>>> help(dir)
Help on built-in function dir in module builtins...is used and returns:
for a module object: the module's attributes.
...(END)
基本场景:
如果 dir() 没有参数,则返回当前作用域中的名称列表;否则,返回给定 object 的一个已排序的属性名称列表。...使用 dir()
使用 dir() 可以查看指定模块中定义的名称,它返回的是一个已排序的字符串列表:
>>> import math # 内置模块 math
>>> dir(math)
['__doc...'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
其中,以下划线(_)开头的名称并不是自己定义的