A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_exception_zerodivisionerror.asp below:

Website Navigation


Python ZeroDivisionError Exception

Python ZeroDivisionError Exception

❮ Python Exceptions

Example

A ZeroDivisionError occurs if you try to divide a number with 0:

print(10 / 0)

Try it Yourself » Definition and Usage

The ZeroDivisionError exception occurs when you try to devide a number with 0, and when you perform a modulo operation with 0.

The ZeroDivisionError exception is one of three ArithmeticError

You can handle the ZeroDivisionError in a try...except statement, see the example below.

Modulo With Zero

A ZeroDivisionError occurs if you try to perform a modulo operation with 0:

Exception Handling Example

Handling the ZeroDivisionError in a try...except statement:

try:
  print(10 / 0)
except ZeroDivisionError:
  print("Error in calculation")
except:
  print("Something else went wrong")

Try it Yourself »

❮ Python Exceptions

Track your progress - it's free!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4