Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
When an arithmetic operation exceeds the limits of the variable type, an OverflowError is raised. Long integers allocate more space as values grow, so they end up raising MemoryError. Floating point exception handling is not standardized, however. Regular integers are converted to long values as needed.
Given code is rewritten to catch exception as follows
i=1
try:
f = 3.0**i
for i in range(100):
print i, f
f = f ** 2
except OverflowError as err:
print 'Overflowed after ', f, err
We get following OverflowError as output as follows