I was doing some experimenting, and I was trying to do this:
import math
for i in range(math.inf):
print(i)
I expected it to be exactly thesame as this:
c = 0
while True:
print(c)
c += 1
But it went more like this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'float' object cannot be interpreted as an integer
Then I tried converting the inf
to a float:
import math
for i in range(int(math.inf)):
print(i)
But that gave me this error saying you can't convert float infinity to an integer.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: cannot convert float infinity to integer
Now my question is why this happens and why infinity is a float in the first place. Is it because of some underlying mathematical law or is this a solution to some problem that arose from doing it otherwise?
Thanks in advance!