Re: [問題] import 問題
※ 引述《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
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章