Equivalent of a?b:c in Python

0 votes
What should I do if I want to print out a string in python. I don't want to use the following:

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

The best option is print ['M', 'F'][int(isfemale_bit)]? But is there any better alternative?
Jan 7 in Python by ana1504.k
• 6,110 points
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
In Python 2.5, you can use ternary conditionals like this:

a if b else c
answered Jan 7 by SDeb
• 9,660 points

Related Questions In Python

0 votes
1 answer

The equivalent of a GOTO in python ​​

Gotos are universally reviled in computer science ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 56,120 points
44 views
0 votes
0 answers
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
65 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
425 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
25 views
0 votes
1 answer

floor of a float in python

As long as your numbers are positive, ...READ MORE

answered Nov 22, 2018 in Python by SDeb
• 9,660 points
29 views
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 9,660 points
101 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.