Code with the error

growth = 2.0 ** 5000
print(growth)

Error message (Python 3.12, last line)

OverflowError: (34, 'Numerical result out of range')

Corrected code

growth = 2 ** 5000
print(len(str(growth)))

Output

1506

Common causes

  • A float is raised to a very large power.
  • A huge whole number is converted with float().
  • The / operator divides a huge whole number, and the result must be a float.
  • A value in a loop is multiplied again and again by mistake.

Practise in the course

Lesson: Math Operations

Frequently asked questions

Can whole numbers overflow in Python?

No. int grows as long as there is memory; the limit applies to float.

What is the largest float?

About 1.8 times 10 to the power 308.