vendredi 28 septembre 2018

Writing if statements as one-liners

I want to write one-liner if statements when i can avoiding two lines of code.

if 10>5:
    print( "10 is greater than 5" )
else:
    print( "nothing here " )

Why the following statement is considered wrong and not being run?

print "10 is greater than 5" if 10>5 else print( "nothing here " )

Aucun commentaire:

Enregistrer un commentaire