python使用特殊命令import导入模块,再以module.function的方式使用模块

python标准库提供了一个专门用于处理复数的模块cmath,math处理数据

 

模块math常用的函数有:

1、ceil  返回大于或等于给定数的最小整数

2、floor  返回小于给定数的最大整数

3、sqrt  用于计算平方根

>>> import math
>>> math.floor(10.2)
10.0
>>> math.ceil(10.2) 
11.0

>>> math.sqrt(10.2)
3.1937438845342623

 

负数的平方根的计算

>>> math.sqrt(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> 
>>> import cmath
>>> cmath.sqrt(-1)
1j

 

posted on 2018-08-22 16:01  宅女士  阅读(331)  评论(0编辑  收藏  举报