The ternary operator is very useful for a single condition. But support ternary operator different way, not like other programming languages (?:).
Syntax: A if C else BThis first evaluates C; if it is true, A is evaluated to give the result, otherwise, B is evaluated to give the result.
Example
>>> 'true' if True else 'false' 'true' >>> 'true' if False else 'false' 'false'
Also Read : Python Interview Question
