Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

equivalent of `a?b:c` [duplicate]

Tags:

python

Possible Duplicate:
Python Ternary Operator

I want to print out a string in python. I don't want to do:

if isfemale_bit:     print 'F' else:     print 'M' 

The best I have right now is print ['M', 'F'][int(isfemale_bit)]?

Is there a better alternative?

I needs my syntactic sugar!!

like image 806
engineerchuan Avatar asked May 13 '11 17:05

engineerchuan


People also ask

How do I allow duplicates in a primary key?

You can define keys which allow duplicate values. However, do not allow duplicates on primary keys as the value of a record's primary key must be unique. When you use duplicate keys, be aware that there is a limit on the number of times you can specify the same value for an individual key.

What is the meaning of a == b == C in C?

The comparison operator == has left to right associativity. So, an expression like a == b == c. is the same as (a == b ) == c. In your case, a , b , c all having values 0 , the expression turns out to be (0 == 0) == 0.

What is duplicate key in SQL?

The Insert on Duplicate Key Update statement is the extension of the INSERT statement in MySQL. When we specify the ON DUPLICATE KEY UPDATE clause in a SQL statement and a row would cause duplicate error value in a UNIQUE or PRIMARY KEY index column, then updation of the existing row occurs.

What is on duplicate key?

The ON DUPLICATE KEY UPDATE clause can contain multiple column assignments, separated by commas. The use of VALUES() to refer to the new row and columns is deprecated beginning with MySQL 8.0.


1 Answers

In Python 2.5, you can use ternary conditionals like this:

a if b else c 

There is more discussion here: Does Python have a ternary conditional operator?

like image 152
Paul Rosania Avatar answered Sep 22 '22 17:09

Paul Rosania