Introduction
The ternary operator helps you choose between two values quickly in one line. It makes your code shorter and easier to read.
When you want to set a variable based on a simple condition.
When you want to print one message if something is true, and another if it is false.
When you want to return a value from a function depending on a condition.
When you want to avoid writing a full if-else block for a quick choice.