python 肆--模块,cmath复数
来源:互联网 发布:淘宝全球买手是真的吗 编辑:程序博客网 时间:2024/06/05 23:39
上一节,一个人的年龄是22。9,她年龄还没到23,只是取22,则需要floor函数
模块:导入到python以增强其功能的扩展,暂时这么理解
需要import命令来导入math模块,利用math模块中的floor函数:
用import导入模块,按照“模块。函数”的格式用这个模块的函数、
>>> import math>>> math.floor (22.9)22.0>>>
把年龄转换为整数22,用int函数
>>> int(math.floor(22.9))22
math.ceil(22.9)23.0
int(22.9)#把参数转化成整数时会自动向下取整22
类型对象type object
>>> long(math.floor(22.9))22L>>> float(math.floor(22.9))22.0
如果不从不同模块导入多个同名函数,则可以用一下格式:不用每次调用函数时都写上模块的名字
>>> from math import sqrt>>> sqrt(9)3.0
>>> foo = math.sqrt#变量来引用函数>>> foo(9)3.0
sqrt只能处理浮点数,也就是实数,如求负一的平方根:
>>> from math import sqrt>>> sqrt(-1)Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> sqrt(-1)ValueError: math domain error
数学概念里有复数,虚数,则需另外一个模块了cmath(complex math,复数):
>>> import cmath>>> cmath.sqrt(-1)1j
>>> (1 + 3j) * (9 + 4j)(-3+31j)
时光机__future__,导入那些未来成为标准python组成部分的新特性
- python 肆--模块,cmath复数
- python之math,cmath模块
- cmath module(针对复数)
- python cmath的用法
- cmath
- cmath
- cmath
- python 复数
- python复数
- Python:基本运算、基本函数(包括复数)、Math模块、NumPy模块
- python 之复数
- Python实现复数运算
- Cmath函数
- 复数
- 复数
- 复数
- 复数
- 复数
- PHP的ctype函数
- ADB调试介绍
- 有效评审的七个注意事项
- Android 在xml中配置 float 和 integer 值
- 2013.4.8早会
- python 肆--模块,cmath复数
- c++ 野指针
- 多线程的条件变量
- 成功创业者必须具备的9个特质
- IP及Mac地址正则表达式
- XP装fedora
- zscore 是如何标准化矩阵的?
- 获取产品需求的五种方法
- I,P,B帧和PTS,DTS的关系