a = '1'
list_test = []
try:
b = a + 'test'
# 错误语句行及以下,均不会被执行,之前的语句会执行和保存
a = a + 1 # 该句错误
list_test.append(a)
# c = a + 1
# list_test.append(c)
d = 1
except:
print('test complit')
if __name__ == '__main__':
print(a) # 此时依然有 a = '1'
print(b)
# IDE提示name 'b' is not defined
# ??? 实际可以运行,且结果正确
print(list_test)
print(len(list_test))
# print(d)
# 运行终止,报错,NameError: name 'd' is not defined```
对Python异常处理语句try......expect......的一些实践理解
最新推荐文章于 2024-05-22 20:02:27 发布