🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!
🖥️ Exceptions in Python: Execute Code ONLY when NO Exception is Raised (ELSE)
In some situations, you might want to run a certain block of code, IF the code inside the try clause ran without any errors. For these cases, you can use the optional ELSE keyword with the TRY statement in Python, to define a block of code to be executed, if and ONLY if there is no error raised.
Note: Exceptions in the ELSE clause are NOT handled by the preceding EXCEPT clauses.
try:
x = 1/1
except:
print('Something went wrong')
else:
print('Nothing went wrong')
Here is an example that will divide the integer 1 by 1 – and store its result in the variable x. If an error occurs during this process, an exception is raised, then the except clause will catch and handle this error – printing out ‘Something went wrong’. ELSE, it will print out ‘Nothing went wrong’ because the program did not run into any exceptions and the else clause was executed.
That is great! You can catch Exceptions, Handle them properly, and Execute some code when no exceptions are raised. But, How would you execute a block of code even though an error occurred? Let’s find out throughout the next video…
Let’s play this video, stick around and watch until the end of this video! 👍🏻
– Digital Academy™ 🎓
***
☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho
☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw
📖 Blog: http://digital.academy.free.fr/blog/
📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners
🛒 Shopping and Discounts: http://digital.academy.free.fr/store
#Python #Tutorial #Beginners #Shorts
***
♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.
***
♡ FOLLOW US ♡
✧ http://digital.academy.free.fr/
✧ https://twitter.com/DigitalAcademyy
✧ https://www.facebook.com/digitalacademyfr
✧ https://www.instagram.com/digital_academy_fr/
✧ https://www.youtube.com/c/DigitalAcademyOnline
♡ SUPPORT US ♡
✧ http://digital.academy.free.fr/join
✧ http://digital.academy.free.fr/donate
✧ http://digital.academy.free.fr/subscribe
✧ https://www.patreon.com/digital_academy
✧ https://www.buymeacoffee.com/digital_academy
***