Best Answer · By JanBask Python Expert
Answered on Mar 2, 2021
To condense if/else into one line in Python an example of Python's way of doing "ternary" expressions:-
i = 5 if a > 7 else 0
Translates into:-
if a > 7:
i = 5
else:
i = 0
Was this helpful?