Python中的try/except/else/finally
运行下面的例子,应该很容易理解。其中注释掉的两个地方,分别尝试取消注释,运行后自行体会学习。
# coding: utf-8 try: print("<<< 开始执行try语句") #b = 1 a = b print("<<< 你看到本行输出,是因为前一句没有异常的情况下") except SyntaxError: print("<<< SyntaxError") except SystemExit: print("<<< SystemExit") #except: # print("<<< I don't know, but error.") else: print("<<< try语句块中没有异常,输出本行") finally: print("<< 无论有没有except,都会执行finally里的语句。如果有没处理的except,咱到这儿就结束;没except的话接着执行后面的正常语句") print('<<< hey, try/except/else is not difficult!')
相关推荐
寻常白昼 2020-08-15
HMHYY 2020-07-28
loviezhang 2020-06-16
lsfreeing 2020-06-11
sunlizhen 2020-06-01
Yasin 2020-05-14
czsay 2020-05-09
wqbala 2020-03-04
会哭的雨 2020-02-19
awoyaoc 2020-02-02
czsay 2020-01-31
xiaoxiaoniaoer 2020-01-29
猛禽的编程艺术 2020-01-16
xinhao 2020-01-14
TinyDolphin 2020-01-14
Winterto0 2020-01-07
lustdevil 2019-12-31
wangyjbk 2019-12-27