← Back to Error Guide
ZeroDivisionError

How to Fix ZeroDivisionError

Understanding and resolving ZeroDivisionError in Python

What is ZeroDivisionError?

A ZeroDivisionError occurs when you try to divide a number by zero, which is not allowed.

Common Causes

Common causes of this error...

How to Fix

Wrong Code

# Code that causes the error
result = 10 / 0

Correct Code

# Fixed code
denominator = 0
if denominator != 0:
    result = 10 / denominator
else:
    result = 'Undefined, cannot divide by zero'

More Python Error Guides