Python 3.6.5
使用这个答案math作为指导,我尝试查看是否导入了某些模块,例如。
但 Python 告诉我它们都被导入了,而实际上它们并没有导入。
>>> import sys
>>> 'math' in sys.modules
True
>>> 'math' not in sys.modules
False
>>> math.pi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined
>>> import math
>>> 'math' in sys.modules
True
>>> math.pi
3.141592653589793
Run Code Online (Sandbox Code Playgroud) python ×1