Python中内置的dir函数用于显示模块中定义的标识符的, 包括函数、变量、类等 dir()函数的参数可以是模块,也可以是类、函数等
举例
dir
Out[
13]: <
function dir> #说明dir是一个function
type(dir)
Out[14]: builtin_function_or_method
dir() #如果没有参数,则显示当前模块包含的标识符
Out[
15]:
[
'In',
'Out',
'_',
'_1',
'_10',
'_11',
'_12',
'_13',
'_14',
'_2',
'_3',
'_5',
'_6',
'_7',
'_9',
'__',
'___',
'__builtin__',
'__builtins__',
'__doc__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'_dh',
'_i',
'_i1',
'_i10',
'_i11',
'_i12',
'_i13',
'_i14',
'_i15',
'_i2',
'_i3',
'_i4',
'_i5',
'_i6',
'_i7',
'_i8',
'_i9',
'_ih',
'_ii',
'_iii',
'_oh',
'_sh',
'exit',
'get_ipython',
'np',
'quit']
zzzzz =
1
dir()
Out[
17]:
[
'In',
'Out',
'_',
'_1',
'_10',
'_11',
'_12',
'_13',
'_14',
'_15',
'_2',
'_3',
'_5',
'_6',
'_7',
'_9',
'__',
'___',
'__builtin__',
'__builtins__',
'__doc__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'_dh',
'_i',
'_i1',
'_i10',
'_i11',
'_i12',
'_i13',
'_i14',
'_i15',
'_i16',
'_i17',
'_i2',
'_i3',
'_i4',
'_i5',
'_i6',
'_i7',
'_i8',
'_i9',
'_ih',
'_ii',
'_iii',
'_oh',
'_sh',
'exit',
'get_ipython',
'np',
'quit',
'zzzzz'] #新增一个变量zzzzz
import numpy
as np
dir(np) #查看numpy包中的标识符(输出太长了不列了)
type(np.ndarray)
Out[
21]:
type #ndarray是numpy里面定义的一种数据类型
dir(np.ndarray) # 列出ndarray中的标识符(输出太长了不列了)
Out[
22]: