执行过程中出错,复制错误信息,利用TRY得到相应的错误,并用特别方法解决:

print(3/0)
提示:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
print(3/0)
ZeroDivisionError: division by zero
红色为错误提示:    
解决思路: 

写好程序,调试过程中如果反复没有规律地出错,找到错误类型提示,捕获,并用特别方法解决 :pass,break,continue,

try:
    print(3/0)
except ZeroDivisionError as e:
    print("0不能做除数") 

相关文章:

  • 2021-06-16
  • 2022-12-23
  • 2021-04-03
  • 2022-02-28
  • 2021-06-10
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2021-11-02
  • 2021-09-06
  • 2021-06-28
  • 2022-12-23
  • 2022-02-03
相关资源
相似解决方案