lundi 5 février 2018

else executed with if inside of for

I have a problem with 'if' executed together with 'else' when the value is equal to zero, the indentation seems fine so else is not part of for-else loop:

for i in range(0,5):
    if i == 0:
        print("i0 =", i)
    if i == 2:
        print("i2 =", i)
    else:
        print("else i=", i)


i0 = 0
else i= 0
else i= 1
i2 = 2
else i= 3
else i= 4
>>> 

Aucun commentaire:

Enregistrer un commentaire