您的位置:首页 > 编程语言 > Python开发

python 内建函数功能函数 abs() coerce() divmod() round() pow()

2016-10-10 15:49 525 查看
>>> abs(-1)
1
>>> abs(10.)
10.0
>>> abs(1.2-2.1j)
2.4186773244895647
>>> abs(0.22-0.77)
0.55
>>> coerce(1,2)
(1, 2)
>>>
>>> coerce(1.3,134L)
(1.3, 134.0)
>>>
>>> coerce(1,134L)
(1L, 134L)
>>> coerce(1.23-41j,134L)
((1.23-41j), (134+0j))
>>>
>>> divmod(10,3)
(3, 1)
>>> divmod(3,10)
(0, 3)
>>> divmod(10,2.5)
(4.0, 0.0)
>>> divmod(2.5,10)
(0.0, 2.5)
>>> divmod(2+1j,0.5-1j)
((-0+0j), (2+1j))
>>>
>>> pow(2,5)
32
>>> pow(5,2)
25
>>> pow(1+1j,3)
(-2+2j)
>>>
>>> round(3)
3.0
>>> round(3.45)
3.0
>>> round(3.4999,1)
3.5
>>> import math
>>> for eachnum in range(10):
print round(math.pi,eachnum)

3.0
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159265
3.141592654
>>> round(-3.49,1)
-3.5
>>> round(-3.49)
-3.0
>>> round(0.5)
1.0
>>> round(-0.5)
-1.0
>>>

abs():返回参数的绝对值

coece():数据类型转换函数,返回一个包含类型转换完毕的两个数值元素的元组

divmod():内建函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组。

round():用于对浮点数进行四舍五入运算

pow():进行指数运算
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: