Hi there,

this is rather a philosophical question, but I assume I miss something. I don't remember I ever used else clause for years I was with python and my expectation was it executed only if the the main body was never run. Ha-ha! I was caught by this mental trap.

So, seriously, why they needed else if the following pieces produce same result? Does anyone know or remember their motivation?

Just curious.

Axy.

print('--- with else')


for i in [1,2,3]:
    print(i)
else:
    print(4)

for i in []:
    print(i)
else:
    print(5)

print('--- without else')

for i in [1,2,3]:
    print(i)
print(4)

for i in []:
    print(i)
print(5)
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to