numeric limits in python?
I don't think there exist such constants, no (of course, they could be hiding somewhere...)
Python ints are guaranteed to be 32 bits. When they overflow, they are automatically converted to longs, which are not limited in size (except by how much memory you have).
int_min would be -(2**31) and int_max would be 2**31-1
Python ints are guaranteed to be 32 bits. When they overflow, they are automatically converted to longs, which are not limited in size (except by how much memory you have).
int_min would be -(2**31) and int_max would be 2**31-1
Are they guaranteed to be 32 bits? Last time I checked for the C Python distribution they were implemented using longs so they are at least 32 bits, but may be greater, depending on the compiler used to build the Python interpreter.
Ok, I was hoping to use those values to initialize some data like:
def findMin( list ):
min = some_const_for_max
for s in list:
if s < min:
min = s
...
but that doesn't really make sense if there is no limits on integer numbers.
def findMin( list ):
min = list[0]
...
works just the same...
Thanks for the info
def findMin( list ):
min = some_const_for_max
for s in list:
if s < min:
min = s
...
but that doesn't really make sense if there is no limits on integer numbers.
def findMin( list ):
min = list[0]
...
works just the same...
Thanks for the info
Alternatively, just use the built-in functions min() and max(). No need to write them yourself.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement