模块
命令行 ide shell python到底是什么关系 怎么使用??
1.当我们import来调用一个模块的时候,我们会先把这个被调用的模块运行一遍,因此被调模块中的输出同样会被输出。
#block.py
if __name__=='__main__':
print('itself')
else:
print('another')
#string.py
print('hello\nrunoob')
print(r'hello\nrunoob')
import block
block.py的结果:
string.py的结果:
2.dir()函数命令返回当前对象的名称列表
#在命令行或shell中
import sys
dir(sys)
dir()
a=5
dir()
del a
dir()
del sys
dir()
import sys
dir()
3.包
包包含模块及特殊的文件夹“__init__.py”