理解StopIteration的异常
在讲循环对象的时候,曾提到一个StopIteration的异常,该异常是在循环对象穷尽所有元素时的报错。我们以它为例,来说明基本的异常处理。一个包含异常的程序:a = iter(range(5))try: for i in range(100): print(a.__next__())except StopIteration: print('here is end ', i)# 结果展示:'''01234here is end 5'''首
原创
2020-09-21 17:08:27 ·
7209 阅读 ·
0 评论