Python - One line if-elif-else statement

Viewed 17173

I'm trying to condense an if-elif-else statement into one line. I tried:

a == 1 ? print "one" : a == 2 ? print "two" : print "none"

But I got a syntax-error. I have also tried:

print "one" if a == 1 else print "two" if a == 2 else print "none"

But I also got a syntax-error.

What can I do to make any of these answers better or create a working answer?

7 Answers
Related