84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
a=[11,22,33,44,55]
for i in a:
print(i)
else:
print(99)
Result:112233445599This is amazing Why does 99 appearHow should I write for if else?
1.for ... else ... syntax (http://book.pythontips.com/en...)
for i in range(10): #如果没有break,会print所有i print(i) else: #如果上面的for循环没有break,这里会打印 print(99)
2.for if else should refer to the following:
for i in range(10): if i > 5: break else: print(i)
In addition to common conditional judgments in other languages, else in python can also be used in loops. If the break statement is not executed in the for loop, the branch statement under else will be executed
Because the loop is allowed to complete normally, the else branch is also executed
1.for ... else ... syntax (http://book.pythontips.com/en...)
2.for if else should refer to the following:
In addition to common conditional judgments in other languages, else in python can also be used in loops. If the break statement is not executed in the for loop, the branch statement under else will be executed
Because the loop is allowed to complete normally, the else branch is also executed