跳至正文

模組和套件

什麼是模組?

模組是包含Python程式碼的檔案(.py)。它們是重複使用和建構程式碼的核心工具。

# math_utils.py
def add(a, b):
"""對兩個數求和"""
return a + b

def multiply(a, b):
"""兩個數相乘"""
return a * b

PI = 3.14159

# main.py
import math_utils

result = math_utils.add(3, 5)
print(result) # 8

print(math_utils.PI) # 3.14159

[Rest of the content remains the same, translated into Traditional Chinese]

下一步

你已經掌握了模組和套件!

關鍵點:
✅ 模組匯入和from import
✅ __name__和__main__模式
✅ 套件結構和__init__.py
✅ 虛擬環境和pip
✅ 使用requirements.txt管理依賴
✅ 實踐專案結構

下一步:你已完成Python基礎系列!現在在Python實踐系列中建立實踐專案!