import importlib # 動態載入內建模組 math_module = importlib.import_module("math") print(math_module.sqrt(16)) # 4.0 # 動態載入自訂模組 module_name = "my_module" # 假設有 my_module.py custom_module = importlib.import_module(module_name) print(custom_module.hello()) # 假設 my_module 有 hello() 函式