本文介绍了"否则"认为在Python中有害吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中(通过关于Python的的问题尝试...其他声明:

In an answer (by S.Lott) to a question about Python's try...else statement:

三思而后行:一般来说,这是
的问题。除了if-statement中的
之外,请避免使用它,甚至然后
考虑记录else-
条件以使其明确。

Think twice about else:. It is generally a problem. Avoid it except in an if-statement and even then consider documenting the else- condition to make it explicit.

这是一个广泛持有的观点吗? 其他

Is this a widely held opinion? Is else considered harmful?

当然,您可以用它编写令人困惑的代码,但对于任何其他语言构造都是如此。甚至Python的对于......其他在我看来也是一件非常方便的事情(对于来说更少...尝试...其他)。

Of course you can write confusing code with it but that's true of any other language construct. Even Python's for...else seems to me a very handy thing to have (less so for try...else).

推荐答案

S.Lott显然已经看到了一些不好的代码。我们都不是吗?我不认为其他有害的,虽然我已经看到它曾用于编写错误的代码。在这些情况下,所有周围的代码也都很糟糕,所以为什么要责怪其他人?

S.Lott has obviously seen some bad code out there. Haven't we all? I do not consider else harmful, though I've seen it used to write bad code. In those cases, all the surrounding code has been bad as well, so why blame poor else?

这篇关于"否则"认为在Python中有害吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:15