作者sunrise0406 (baker)
看板Python
标题Re: [问题] import 问题
时间Mon Dec 6 13:09:55 2010
※ 引述《shihyuyao (Yao)》之铭言:
: import math
: from math import *
: 这两个有什麽不同?
: 谢谢
不同点在於使用import math 时,math是全域变数,math.fabs就像是使用变数的属性
使用from math import *时,math底下的函式都是全域变数,直接使用函式名称即可。
另外,根据Python Web Development with Django [Forcier et al.]一书所描述,
当你只想用模组中的某一个函式时,使用"import math 和 from math import fabs"并
没有效能上的差别。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.166.94