异常(exceptions)是Python中一种非常重要的类型,它和语法错误不同,是在程序运行期间引发的错误。Python中内置了很多异常,如IOError,NameError,KeyboardInterrupt等,更多的异常可以点击这里。
异常的意义在于提供一种更加优雅的运行方式,例如用Python编写一个计算器,如果用户输入不能计算的对象,则可以抛出异常,并进行处理, 如下:
while True:
try:
x= int(input('Please In enter A nu
立即学习:https://edu.csdn.net/course/play/24797/282200?utm_source=blogtoedu
# raise 异常使用
class Test47:
property
def theAge(self):
return self.__age
theAge.setter
def theAge(self, age):
if age > 30 or age < 10: