Exception handling in python

Pubblicato il: 19 January 2023
sul canale di: Daily Tutorials
6,011
101

This program defines a function divide(x, y) that takes two numbers as input and divides the first by the second.
It uses a try-except block to handle the ZeroDivisionError that can occur when the denominator is zero.
It prints an error message when the exception is caught.
The else clause is executed if the try block completes without raising an exception.
The finally clause is executed after the try and except blocks regardless of whether an exception was raised or not.

In this example the first call of divide(2,1) will print the result as 2.0 and executing finally clause.
The second call of divide(2,0) will print the division by zero! and executing finally clausThis program defines a function divide(x, y) that takes two numbers as input and divides the first by the second.
It uses a try-except block to handle the ZeroDivisionError that can occur when the denominator is zero.
It prints an error message when the exception is caught.
The else clause is executed if the try block completes without raising an exception.
The finally clause is executed after the try and except blocks regardless of whether an exception was raised or not.

In this example the first call of divide(2,1) will print the result as 2.0 and executing finally clause.
The second call of divide(2,0) will print the division by zero! and executing finally claus


In questa pagina del sito puoi guardare il video online Exception handling in python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Daily Tutorials 19 January 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 6,011 volte e gli è piaciuto 101 spettatori. Buona visione!