logo-MindMajix
PostPythonPython
A
Aryan Sharma

Posted on 18th July 2024|118 views

0
votes

Ternary Operator Python

Explain about the ternary operator in python?

1 answers
Answers
P
sri kanth

Posted on 18th July 2024| views

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
Name
Course *
Email *
Phone Number