dimanche 31 janvier 2016

Why doesn't if else shorthand work with break - Python

I have been trying break out of loop when a condition is matched. I've tried one-liners below:

break if a is not None else time.sleep(1)

and this

a is not None and break
time.sleep(1)

Both are not working & throwing SyntaxError while the straight forward works fine.

if a is not None:
    break
time.sleep(1)

While I've no problem with using it this way, I just want to know why the syntax for above is wrong.

Aucun commentaire:

Enregistrer un commentaire