Python Infinity - Any caveats?

Viewed 155883

So Python has positive and negative infinity:

float("inf"), float("-inf")

This just seems like the type of feature that has to have some caveat. Is there anything I should be aware of?

5 Answers

A VERY BAD CAVEAT : Division by Zero

in a 1/x fraction, up to x = 1e-323 it is inf but when x = 1e-324 or little it throws ZeroDivisionError

>>> 1/1e-323
inf

>>> 1/1e-324
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero

so be cautious!

Related