学习目标:Python模块导入与别名
- Python日常
内容展示:
- 使用import 引用Python模块
# 导入Python模块的方式
import math
from math import cos
from math import *
print(math.sin(1.23)) # 0.9424888019316975
print(cos(2.34)) # -0.695563326462902
print(tan(1.23)) # 2.819815734268152
2.指定别名as
import math as m
print(m.sin(20)) # 0.9129452507276277
from math import cos as c
print(c(3)) # -0.9899924966004454
# print(cos(12)) 命名别名后,原来的名字不可使用
小结:在Python语言中可以使用 import 导入模块中的所有成员,也可以使用from … import导入模块中所有或特定成员。并且使用 as 为模块或者模块中的成员指定别名。一旦指定了别名,原来的名字就无效了。
- CSDN Python日常 第1 篇
- 【下一篇链接】
- Pycharm安装链接【待】