The Python language supports the use of the else
keyword as part of the syntax of a for
statement. Most folks steer clear of it because it is an oddity, but it will execute if and only if the for
loop is exited "naturally" - that is without executing break.
For that reason it is sometimes referred to as the "no-break" conditional. In the sample code given in the question, i
is appended to ans
only if the break statement in the for
loop above it is never reached.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…