🔥 Welcome to my blog! Latest updates available now. Visit daily! 🔥 🔥 Click Here for Latest Updates – Visit My Blog 🔥
🔥 Latest Updates 📊 GP Grade Finder 📢 Government Services Info 🆕 New Schemes Updates

Single except block that can handle multiple exceptions in Python

-->We can write a single except block that can handle multiple different types of exceptions.


except (Exception1, Exception2, Exception3, ...):

or

except (Exception1, Exception2, Exception3, ...) as msg:

Parentheses are mandatory and this group of exceptions is internally considered as a tuple.


Example

try:

    x = int(input("Enter First Number: "))

    y = int(input("Enter Second Number: "))

    print(x / y)


except (ZeroDivisionError, ValueError) as msg:

    print("Plz Provide valid numbers only and problem is:", msg)


Output:


D:\Python3>py SingleEx.py

Enter First Number: 10

Enter Second Number: 0

Plz Provide valid numbers only and problem is: division by zero


D:\Python3>py SingleEx.py

Enter First Number: 10

Enter Second Number: ten

Plz Provide valid numbers only and problem is: invalid literal for int() with base 10: 'ten'


No comments:

Post a Comment

Thank you Very Much.For Given Comment

Birth & Death Registration Rules 2026

జనన, మరణాà°² నమోà°¦ు à°µిà°·à°¯ంà°²ో 2026 à°…à°•్à°Ÿోబర్ 1 à°¨ుంà°šి à°•ొà°¤్à°¤ à°¨ిà°¬ంధనలు అమల్à°²ోà°•ి à°°ాà°¨ుà°¨్à°¨ాà°¯ి. 🔹 21 à°°ోà°œుà°²్à°²ోà°ªు: à°¸ాà°§ాà°°à°£ à°°ిà°œిà°¸్à°Ÿ్à°°ేà°·à°¨్ 🔹 21 à°°ోà°œుà°² తర్à°µాà°¤...