Python ZeroDivisionError: Handling Division By Zero (Python 3 )

Python ZeroDivisionError: Handling Division By Zero

As you hopefully know, we can't divide by the number zero. If we do so anyway, Python will throw an exception called ZeroDivisionError, which is a subclass of ArithmeticError. When can catch this exception with a Python try except block.

If you call a Python function inside the try block, and an exception occurs in that function, the flow of code execution stops at the point of the exception and the code in the except block is executed. Try doing this again, without try and except. You'll see that Python prints the exception for us on stderr, causing error output and a non-zero return code from your code.

Edit and run this Python 3 example code

This code is editable and runnable. You can run "Python ZeroDivisionError: Handling Division By Zero" by pressing the run button. It will be executed in our backend and the result (stdout and stderr) is displayed in addition tabs.

Share "Python ZeroDivisionError: Handling Division By Zero"

Share this crumb (Python ZeroDivisionError: Handling Division By Zero) with your friends and colleagues to help them learn more about Python 3 programming.

Twitter, Facebook, LinkedIn

On Twitter, Facebook, and LinkedIn, simply paste the URL in your post and watch the magic unfold.


If you want to embed the crumb in an iframe, use the following code:

oEmbed (WordPress)

We support oEmbed, but most sites use allowlisting. On WordPress, oEmbed is supported out of the box, but see the note below.

If you plan to use heavily on Wordpress, you can use the following PHP code to allowlist our site and unlock all the functionalities of our crumbs:
wp_oembed_add_provider( '*', '' ); is a service that allows you to embed content from other sites. We will request to be added to the list of trusted sites once we're out of beta.