Python 模块
来源:互联网 发布:哪种网络电视盒子好 编辑:程序博客网 时间:2024/06/05 16:09
Python其实也是具有模块的概念的,可以把Python模块比作导入到Python中以增强其功能的扩展,需要使用特殊的命令import来导入模块。
math模块 floor代表的取底值,ceil代表的取顶值,fabs代表的是取绝对值,当然了还有许多其他的用法。这里不做一一介绍。
import mathprint("amth取底:",math.floor(32.9));print("math取顶:",math.ceil(32.9));print("math取绝对值:",math.fabs(-1));
为了避免导入多个同名函数,可以用以下方法调用该函数。(from 模块名 import 函数) sqrt代表的是求9的平方根。
from math import powprint("2的4次方的值为:",pow(2,4));from math import sqrtprint("9的平方根为:",sqrt(9));
如果要求-1的平方根怎么办?sqrt会抛出错误。那怎么才能求-1的平方根是多少呢?其实按照数学的标准理论来说负数也是存在平方根的,只不过这个平方根是个虚数。
这就需要用到另一个模块cmath模块了。python语言本身也提供了对复数的支持。
import cmathprint("-1的平方根为:",cmath.sqrt(-1));
以上模块的输出的值分别为:
http://www.jb51.net/article/48433.htm
关于math模块的其它用法可以参考以上文章。
阅读全文
0 0
- python模块 ---logging模块
- python模块-re模块
- python模块 - functools模块
- python 模块 模块文件
- python模块 - pickle模块
- python模块 - copy模块
- python模块
- python 模块
- python-模块
- python 模块
- python模块
- python 模块
- python模块
- python 模块
- python 模块
- 模块-python
- python 模块
- python模块
- 由浅入深JavaScript12进阶-事件2
- Python的Object基类__del__方法
- bzoj2005[Noi2010]能量采集
- 树莓派2上运行LSD_SLAM
- HTTP Client MultiThreadedHttpConnectionManager线程安全连接管理类源码解析
- Python 模块
- Struts2学习总结(二):第一个Struts2程序
- jQuery兼容浏览器IE8方法
- nodejs 设置中文cookie无效
- [LeetCode] 205. Isomorphic Strings
- SpringMVC整合TaskExecutor线程池的配置/使用
- LZO词典压缩器程序实现
- java.lang.NullPointerException:com.cloudera.server.cmf.cluster.RulesCluster createServicesIfNeeded
- 参于一个项目代码的维护与迭代的第一步——从代码仓库的提交记录着手(了解历史有利于前行)