

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Does Python have a ternary conditional operator?
Ternary operator was added in Python 2.5. Its syntax is:
Syntax
x if expr==True else y
Example
Following example illustrates usage
>>> percent=59 >>> 'pass' if percent>=50 else 'fail' 'pass' >>> percent=45 >>> 'pass' if percent>=50 else 'fail' 'fail'
- Related Questions & Answers
- Conditional ternary operator ( ?: ) in C++
- What is a Ternary operator/conditional operator in C#?
- How to implement ternary conditional operator in MySQL?
- Ternary Operator in Python?
- How to overload python ternary operator?
- Changing ternary operator into non-ternary - JavaScript?
- Ternary Operator in C#
- Ternary Operator in Java
- Java Ternary Operator Examples
- C/C++ Ternary Operator
- What is a ternary operator (?:) in JavaScript?
- Ternary Operator in Dart Programming
- How can we use Python Ternary Operator Without else?
- What is ternary operator in C#?
- How Ternary operator in PowerShell Works?
Advertisements