coerce:返回一个包含类型转换完毕的两个数值元素的元组。
>>> coerce(1.3,134L)
(1.3, 134.0)
divmod:把除数和取余结合起来:
>>> divmod(10,3)
(3, 1)
>>> divmod(1.1,3.2)
(0.0, 1.1)
round:四舍五入
>>> round(3.4999999999999999)
4.0//why?
>>> round(3.499999999999999)
3.0
hex:转为16进制
>>> hex(16)
'0x10'
>>> hex(0011)//这个可以看作8进制的11
'0x9'
oct:转为8进制
>>> oct(11)
'013'
>>> oct(0x11)
'021'
ord:ASCII转数字
>>> ord('a')
97
>>> ord(0)
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
ord(0)
TypeError: ord() expected string of length 1, but int found
>>> ord('0')
48
数字函数
原创
©著作权归作者所有:来自51CTO博客作者xiangjie256的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:isinstance判断对象
下一篇:遍历,enumerate
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
摘要 数字签名 数字证书 加密 国密 OpenSSL OpenSSH
摘要 数字签名 数字证书 国密 对称加密 非对称加密 openssl工具 openssh
加密算法 数字签名 数字证书 国密 对称加密 -
在mysql中returns
操作MySQL数据库向
在mysql中returns 表名 数据 数据库