您的位置:首页 > 编程语言 > Python开发

python dir()内建函数

2016-07-22 16:51 387 查看
在python集成开发环境中,了解内建函数dir的属性内容及其类型,同时输出它的文档字符串内容。
print dir
print dir()
print type(dir)
print dir.__doc__
下面是它的输出:

<built-in function dir>

['In', 'Out', '_', '__', '___', '__builtin__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_dh', '_i', '_i1', '_i10', '_i11', '_i2', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', '_sh', 'a', 'aver', 'b',
'de', 'exit', 'flag', 'get_ipython', 'i', 'num', 'pystr', 'quit', 's']

<type 'builtin_function_or_method'>

dir([object]) -> list of strings

If called without an argument, return the names in the current scope.

Else, return an alphabetized list of names comprising (some of) the attributes

of the given object, and of attributes reachable from it.

If the object supplies a method named __dir__, it will be used; otherwise

the default dir() logic is used and returns:

for a module object: the module's attributes.

for a class object: its attributes, and recursively the attributes

of its bases.

for any other object: its attributes, its class's attributes, and

recursively the attributes of its class's base classes.

可以看到dir是内建函数名,它的类型是内建函数或者方法。通过文档字符串,可以了解它的功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 函数