脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python3中的最大整数和最大浮点数实例

Python3中的最大整数和最大浮点数实例

2021-08-05 00:33Lavi Python

今天小编就为大家分享一篇Python3中的最大整数和最大浮点数实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

Python中的最大整数

Python中可以通过sys模块来得到int的最大值. python2中使用的方法是

?
1
2
3
import sys
max = sys.maxint
print (max)

python3中使用的方法是:

?
1
2
3
import sys
max = sys.maxsize
print (max)

Python中获得最大浮点数

方法一:使用sys模块

?
1
2
3
4
5
6
7
>>> import sys
>>> sys.float_info
sys.floatinfo(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2
250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsil
on=2.2204460492503131e-16, radix=2, rounds=1)
>>> sys.float_info.max
1.7976931348623157e+308

方法二:使用float函数

?
1
2
3
4
5
>>> infinity = float("inf")
>>> infinity
inf
>>> infinity / 10000
inf

以上这篇Python3中的最大整数和最大浮点数实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/liuweiyuxiang/article/details/80590235

延伸 · 阅读

精彩推荐