OneCompiler

Ternary operator in Python?

We have ternary operators in languages like C, C++ and many more. Is there anything similar to that in Python?

1 Answer

5 years ago by

Ternary operators makes if else statements compact and these are added to python in version 2.5

Syntax:

[on_true] if [expression] else [on_false] 
5 years ago by Divya