3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
PYTHON機器學習自學/自修 整理[00021] ~ Python – 100天从新手到大师(06.函数和模块的使用.md) module1.py def foo(): print('hello, world!') module2.py def foo(): print('goodbye, world!') test.py import module1 as m1 # as等同 SQL的(別名)用法 import module2 as m2 m1.foo() m2.foo() ————– 但是如果將代碼寫成了下面的樣子,那麼程序中調用的是最後導入的那個foo,因為後導入的foo覆蓋了之前導入的foo。 test.py from module1 import foo # 只從模組載入特定函數使用 from module2 import foo # 输出goodbye, world! foo()

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦