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!!
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.
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.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With