try:
x,y = 10,20
a = x/y
print(a)
except:
print("除错误和A没有定义");
#==================================================
class shortInputException(Exception):
def __init__(self, length, atleast):
Exception.__init__(self)
self.length = length
self,atleast = atleast
try:
s = input('请输入三个以上字符:')
if len(s) < 3:
raise shortInputException(len(s), 3)
except shortInputException as x:
print ('shortInputException: 长度是 %d, 至少应该是 %d' % (x.length, x.atleast))
else:
print ('没有发生异常')
===================================================
a = 1
b = 2
c = 8
try :
assert a < b
d = a + c
print (d)
except AssertionError: #断言语句失败
print ('a>b,语句表达式数据类型错误')
except TypeErrot as e:
print ('语句表达式数据类型错误', e)
======================================================
Powered by ddoss.cn 12.0
©2015 - 2025 ddoss
渝公网安备50011302222260号
渝ICP备2024035333号
【实验平台安全承诺书】
小绿叶技术社区,优化网络中,点击查看配置信息
主机监控系统: 安全防火墙已开启检查cc攻击-下载文件完成后等待10s 恢复访问,检查连接数低于峰值恢复访问
您的IP:216.73.216.110,2025-12-01 14:21:53,Processed in 0.01683 second(s).