I know this is possible:
a, b = 5, 10
print 'a' if a > b else 'b' # outputs b
However, what if I had another variable 'c'? How do I make them print in the same line using the same type of logic as those two variables? Something like?
a, b, c = 5, 10, 20
print 'a' if a > b elif 'b' if b > c else 'c' # is it possible?
Just to mention: I know it's a bad practice, I just wanted to know.
没有elif
,请多次使用else
:
print 'a' if a > b else 'b' if b > c else 'c'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.