这是一些行为特殊的代码。这是我编写的行为的简化版本。这仍然会证明奇怪的行为,我对为什么会发生这种情况有一些具体的问题。
我在 Windows 7 上使用 Python 2.6.6。
def demo1():
try:
raise RuntimeError,"To Force Issue"
except:
return 1
else:
return 2
finally:
return 3
def demo2():
try:
try:
raise RuntimeError,"To Force Issue"
except:
return 1
else:
return 2
finally:
return 3
except:
print 4
else:
print 5
finally:
print 6
结果:
>>> print demo1()
3
>>> print demo2()
6
3
- 为什么演示一返回 3 而不是 1?
- 为什么演示 2 打印 6 而不是打印 6 w/4 或 5?