one liner if else replacement in python

Solutions on MaxInterview for one liner if else replacement in python by the best coders in the world

showing results for - "one liner if else replacement in python"
Prakash
25 Nov 2017
1>>> i=100
2>>> a = 1 if i<100 else 2 if i>100 else 0
3>>> a
40
5>>> i=101
6>>> a = 1 if i<100 else 2 if i>100 else 0
7>>> a
82
9>>> i=99
10>>> a = 1 if i<100 else 2 if i>100 else 0
11>>> a
121
13
Célestine
03 Aug 2016
1>>> a = "Hello" if foo() else "Goodbye"
2