English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Explain the Ternary operator with examples. - Computer Science

Advertisements
Advertisements

Question

Explain the Ternary operator with examples.

Short Note

Solution

Conditional operator:

The ternary operator is also known as the conditional operator that evaluates 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

shaalaa.com
Tokens
  Is there an error in this question or solution?
Chapter 5: Python - Variables and Operators - Evaluation [Page 66]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 12 TN Board
Chapter 5 Python - Variables and Operators
Evaluation | Q 3. | Page 66
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×