from math import *
*代表导入所有的变量,例如
- 使用pi,不需要写为math.pi,直接使用pi
- 使用log,不需要使用math.log,直接使用log
import math
math.log(32,2)
5.0
log(32,2)
Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'log' is not defined
from math import *
log(32, 2)
5.0
可能出现在不同模块中含有相同的名称,都用*导入的话,名称冲突,可能不容易检查出来。尽量用什么功能导入什么功能吧。