Programming Tip -How to handle exception inside a Python for loop?

in #utopian-io6 years ago

Programming Tip -How to handle exception inside a Python for loop?

EBOOK_PYTHON_no-name.png


Today i am going to show Programming Tip - How to handle exception inside a Python for loop
with simple code. I hope you will understand this.
If you have any query you can ask.
i hope you will like it.


This doesn't cause any issues. For example,

for i in range(5):
   try:
      if i % 2 == 0:
         raise ValueError("some error")
      print(i)
except ValueError as e:
   print(e)


This will give the output

some error
1
some error
3
some error


Follow me at : https://steemit.com/@ahmadhassan
=========================================================


Thanks for reading and always welcome your suggestions :) =========================================================

Sort:  

This post has received a 1.30 % upvote from @booster thanks to: @ahmadhassan.

Coin Marketplace

STEEM 0.35
TRX 0.12
JST 0.040
BTC 70887.21
ETH 3581.98
USDT 1.00
SBD 4.75