How to use equivalent C/C++ short-form if (conditional ternary operator) in Python

2 Answers

0 votes
a = 12
b = 20
 
c = a > b and a or b

# ? : swapped to and or
 
print(c)
 
 
'''
run:
 
20
 
'''

 



answered May 26, 2017 by avibootz
edited May 26, 2017 by avibootz
0 votes
a = 12
b = 20

c = a if a > b else b

print(c)


'''
run:

20

'''

 



answered May 26, 2017 by avibootz

Related questions

2 answers 322 views
2 answers 331 views
1 answer 233 views
4 answers 282 views
...