multiple if else condition in single line in python

Solutions on MaxInterview for multiple if else condition in single line in python by the best coders in the world

showing results for - "multiple if else condition in single line in python"
Eden
29 Jan 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