在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是内建函数名,它的类型是内建函数或者方法。通过文档字符串,可以了解它的功能。