python-3.x 尝试使用“continue”捕获失败[已关闭]

hts6caw3  于 2023-05-23  发布在  Python
关注(0)|答案(1)|浏览(111)

**已关闭。**此问题不符合Stack Overflow guidelines。目前不接受答复。

这个问题似乎不是关于在help center定义的范围内编程。
昨天关门了。
Improve this question
我写了下面的代码。

try:
  print(42/0)
  continue 
except (ZeroDivisionError):
  print("Zero division")
except: 
  print("You made a mistake")
except (ValueError):
  print("Boo!")

代码失败,出现错误
语法错误:“continue”在循环中不正确
这是continue的正确语法,没有缩进错误。
错误的含义是什么?

svmlkihl

svmlkihl1#

你得到这个错误的原因是因为你不需要一个带有tryexcept的continue语句。如果它运行try中的代码,它将不会运行except中的代码。

相关问题