首页 > 解决方案 > 为什么“try...else”在 Python 中是“无效语法”?

问题描述

普通的:

try:
    something may go wrong...
except:
    pass
else:
    others func...

我需要的:

try:
    something may go wrong...
else:
    others func...

'try...else' 不存在有什么原因吗?

标签: pythonpython-3.x

解决方案


如果支持,语法

try:
    something may go wrong...
else:
    others func...

在行为上完全等同于

something may go wrong...
others func...

即你不需要任何特殊的语法


推荐阅读