1.

Explain Ternary operator with examples?

Answer»

Conditional operator:

Ternary operator is also known as conditional operator that evaluate something based on a condition being true or false. It simply allows testing a condition in a single line replacing the multiline if – else making the code compact.

The Syntax conditional operator is,

Variable Name = [on – true] if [Test expression] else [on – false]

Example:

min = 50 if 49 < 50 else 70 # min = 50 min = 50 if 49 > 50 else 70 # min = 70



Discussion

No Comment Found