正在加载图片...
Try Statements Try statements handle exceptions try: <try suite> except <exception class>as <name>: <except suite> Execution rule: 1.The <try suite>is executed >>>try first ...X=1/0 2.If,during the course of except ZeroDivisionError as e: executing the <try suite>,an print('Except a',type(e)) exception is raised that is X=0 not handled otherwise then Except a <class 'ZeroDivisionError'> the <except suite>is >>>X executed with <name> 0 bound to the exceptionTry Statements Try statements handle exceptions try: <try suite> except <exception class> as <name>: <except suite> Execution rule: 1. The <try suite> is executed first 2. If, during the course of executing the <try suite>, an exception is raised that is not handled otherwise then the <except suite> is executed with <name> bound to the exception >>>try ... x = 1/0 ... except ZeroDivisionError as e: ... print('Except a', type(e)) ... x = 0 Except a <class ‘ZeroDivisionError’> >>> x 0
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有