Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ternary operator [duplicate]

Tags:

python

Possible Duplicate:
Ternary conditional operator in Python

var foo = (test) ? "True" : "False"; 

What would this look like in Python?

Using Python 2.7 if that makes a difference.

like image 387
cynicaljoy Avatar asked Nov 05 '10 04:11

cynicaljoy


1 Answers

PEP 308 adds a ternary operator:

foo = "True" if test else "False" 

It's been implemented since Python 2.5

like image 140
Brian McKenna Avatar answered Oct 06 '22 10:10

Brian McKenna