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():进行指数运算
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():进行指数运算
相关文章推荐
- python 内建函数功能函数 abs() coerce() divmod() round() pow()
- 功能函数,绝对值abs,数据类型转换coerce,把除法和取余结合divmod,指数运算pow,四舍五入round
- python每日一函数 - divmod数字处理函数
- Python常用函数总结二(complex, delattr, divmod, enumerate, eval)
- python 中的divmod数字处理函数浅析
- python divmod()函数
- python函数日积月累 basestring()、any()、all()、callable()、divmod()
- python 函数 —— divmod()
- Python函数-divmod()
- python之函数用法divmod
- python中的divmod()函数以及求二进制的方法
- Python的内置方法,abs,all,any,basestring,bin,bool,bytearray,callable,chr,cmp,complex,divmod
- Python的内置方法,abs,all,any,basestring,bin,bool,bytearray,callable,chr,cmp,complex,divmod
- Python 内建函数 - divmod(a, b)
- python int() round() floor()函数的比较
- 两篇文章掌握Python语法和内置函数功能(第二篇)
- 【Codeforces Round 276 (Div 2)D】【数论 正难则反 枚举倍数 二分 O(nlogn)】Maximum Value n个数大数mod小数找最大余数
- 【python】详解time模块功能asctime、localtime、mktime、sleep、strptime、strftime、time等函数以及时间的加减运算
- Python中非常实用的一些功能和函数分享