python - for else
学习ing
学习ing 2017-06-12 09:23:44
0
3
892

a=[11,22,33,44,55]

for i in a:

print(i)

else:

print(99)

Result:
11
22
33
44
55
99
This is amazing Why does 99 appear
How should I write for if else?

学习ing
学习ing

reply all (3)
扔个三星炸死你

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

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!