Java, c, c++ both have syntactic sugar like this:
int a = condition ? c : d// if condition is true , a = c, else a = d
Do python have similar syntactic sugar?
Java, c, c++ both have syntactic sugar like this:
int a = condition ? c : d// if condition is true , a = c, else a = d
Do python have similar syntactic sugar?
Python doesn't have a classic "?" ternary operator, but does have a similar construct:
result = 'I am True' if condition else 'I am False'
see the example:- python ternory operator
syntax:- a if test else b
In [54]: 'true' if True else 'false'
Out[54]: 'true'
so that:-
In [52]: a = 5 if 2> 3 else 3
In [53]: a
Out[53]: 3