Posted on 26th April 2024
The ternary operator in Python is also called as conditional expressions which evaluate anything based on condition true or false; this is added to python 2.5. It just lets testing a condition within a single line substituting the multiline if-else creating the code compact.
Syntax: [true statement] if [expression] else [false statement]
Example:
x, y = 12, 30
min = x if x < y else y
print(min)
STILL GOT QUERIES?