Conditional Expression

say it: “kun-DISH-un-ul ek-SPRESH-un” /kənˈdɪʃənəl ɪkˈsprɛʃən/

Picks one of two values in one line: this if condition else that.

What is a conditional expression?

A conditional expression picks one of two values in a single line: this if condition else that.

age = 20
ticket = "adult" if age >= 18 else "child"
print(ticket)  # adult

Level: Journeyman · More Python terms at this level

Updated