Represent infinity as an integer in Python 2.7 -
i wondering how define inf
, -inf
int
in python 2.7. tried , seems inf
, -inf
work float
.
a = float('-inf') # works b = float('inf') # works c = int('-inf') # compile error, valueerror: invalid literal int() base 10: 'inf' d = int('inf') # compile error, valueerror: invalid literal int() base 10: 'inf'
to summarise said in comments
there no way represent infinity integer in python. matches behaviour of many other languages. however, due python's dynamic typing system, can use float('inf')
in place of integer, , behave expect.
as far creating 'double' infinity, in python there 1 floating point type, called float
, unlike other languages such java uses term float , double floating point numbers different precision. in python, floating point numbers use double-precision, act same doubles in java.
Comments
Post a Comment