【发布时间】:2016-06-24 08:13:09
【问题描述】:
def no():
try:
x = eval(input('Enter a number: '))
y = eval(input("Enter a number: "))
print(x/y)
except (ZeroDivisionError, TypeError) , e:
print('The second number cannot be zero!', e)
如何在 3.** python 中完成这项工作
【问题讨论】:
-
您应该始终使用
as e而不是, e。它适用于 Python2 和 Python3,因此使用as使其双向兼容。 -
@zondo:这在 Python 2.5 或更早版本中不起作用。
标签: python exception try-catch except