del <模块名> 就能移除模块,清除环境
[]: import numpy as np
[]: np.pi
[]: Out[41]: 3.141592653589793
[]: del np
[]: np.pi
Traceback (most recent call last):
File "D:\ROOT\AppliedWare\python3\lib\site-packages\IPython\core\interactiveshell.py", line 3291, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-43-fcf8569aec5c>", line 1, in <module>
np.pi
NameError: name 'np' is not defined
本文介绍了在Python环境中如何使用del语句移除已导入的模块,通过实例演示了del语句的使用方法,以及在模块被成功移除后尝试访问该模块属性时将引发NameError异常。
2万+

被折叠的 条评论
为什么被折叠?



