Ternary conditional operators in Python

January 25, 2019

Ternary operators are offered in most programming languages, and are great for simple conditionals. Now you might ask:

Does Python have a ternary operator?

The answer is yes:

age = 19

// Ternary operator
message = "User is of age" if age > 18 else "User is under age"