import time
d = { 'a' : '1'}
def f():
count = 0
while True:
if count % 2 == 0:
print("success")
print(d['a'])
time.sleep(3)
count += 1
else:
print("below fail")
print("below fail")
print("below fail")
print("below fail")
print("below fail")
except:
print("error")
count += 1
time.sleep(3)
finally:
print("start")
f()
d = { 'a' : '1'}
def f():
count = 0
while True:
try:
#正确的路线走完直接到finally
print(count)if count % 2 == 0:
print("success")
print(d['a'])
time.sleep(3)
count += 1
else:
print("fail")
走到这里会报错。执行finally
print("below fail")
print("below fail")
print("below fail")
print("below fail")
print("below fail")
except:
print("error")
count += 1
time.sleep(3)
finally:
print("final")
输出完final之后打印下面outside try
不会打印outside while
print("outside try")
重新回到try开始新的循环
print("start")
f()