导入
使用库
了解 Python 中的库是什么,以及如何创建自定义库并将其导入到其他代码中。
def add(a, b): return a + b
def subtract(a, b): return a - b
def multiply(a, b): return a * b
def divide(a, b): return a / b
导入自定义库
from educative_math_library import add, subtract print(add(5, 7)) print(subtract(5, 7))
导入自定义库
import educative_math_library as math
使用 math 模块中的函数
print(math.add(5, 7)) print(math.subtract(5, 7)) print(math.divide(10, 2)) print(math.multiply(5, 7))