🔥 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

à°†ంà°§్à°°à°ª్à°°à°¦ేà°¶్‌à°²ో సదరం సర్à°Ÿిà°«ిà°•ేà°Ÿ్ à°•ోà°¸ం à°Žà°¦ుà°°ుà°šూà°¸్à°¤ుà°¨్à°¨ à°¦ిà°µ్à°¯ాంà°—ులకు à°¸్à°²ాà°Ÿ్ à°¬ుà°•ింà°—్ à°…à°ª్‌à°¡ేà°Ÿ్.

à°‡ంతకుà°®ుంà°¦ు వరకు SADAREM Slot Booking à°ª్à°°à°•్à°°ిà°¯ à°¸్వర్à°£ à°—్à°°ాà°®ం à°¸్వర్à°£ à°µాà°°్à°¡ు à°¦్à°µాà°°ా à°®ాà°¤్à°°à°®ే à°…ంà°¦ుà°¬ాà°Ÿుà°²ో à°‰ంà°¡ేà°¦ి. à°ª్à°°à°¸్à°¤ుà°¤ం à°ª్రజలకు మరింà°¤ à°¸ౌà°•à°°్యవం...