模块和包

1.引入模块

    import module1[, module2[,... moduleN]]

     调用方式:模块名.函数名

# 导入模块
import hello
 
# 现在可以调用模块里包含的函数了
hello.sayhello()

     from modname import name1[, name2[, ... nameN]]

    调用方式:from 模块名 import 函数名(* 表示引入所有的函数)

## 直接导入方法
from hello import sayhello
sayhello()

 2 .引入包

     包路径下必须存在 __init__.py 文件。

      import 包名.包名.模块名

# 导入包
import cal.calculator
# 使用包的模块的方法
print(cal.calculator.add(1,2))

# 导入包
from cal import calculator
# 使用包的模块的方法
print(calculator.multiply(3,6))
原文地址:https://www.cnblogs.com/lu51211314/p/11808357.html