メインコンテンツにスキップ

モジュールとパッケージ

モジュールとは?

モジュールはPythonのコードが含まれるファイル(.py)です。コードを再利用し、構造化するための基本的なツールです。

# math_utils.py
def add(a, b):
"""2つの数を足します"""
return a + b

def multiply(a, b):
"""2つの数を掛けます"""
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 Japanese]

次のステップ

モジュールとパッケージをマスターしました!

主要ポイント:
✅ モジュールのインポートとfrom import
✅ __name__と__main__のパターン
✅ パッケージ構造と__init__.py
✅ 仮想環境とpip
✅ requirements.txtによる依存関係管理
✅ 実践的なプロジェクト構造

次のステップ: Python Basicsシリーズを完了しました!Python Practicalシリーズで実践的なプロジェクトを作成しましょう!