Post

PythonPython

A
Aryan Sharma

Posted on 26th April 2024|117 views

0
votes

Ternary Operator Python

Explain about the ternary operator in python?

Answers
P
sri kanth

Posted on 26th April 2024

The ternary operator in Python is also called as conditional expressions which evaluate anything based on condition true or false; this is added to python 2.5. It just lets testing a condition within a single line substituting the multiline if-else creating the code compact. 

Syntax: [true statement] if [expression] else [false statement]  

Example:

x, y = 12, 30

min = x if x < y else y

print(min)

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos