hobbes3 hobbes3 - 8 months ago 33
Python Question

Is there a way to add a conditional string in Python's advance string formatting "foo {}".format(bar)?

For example I have a line of code like this

if checked:
checked_string = "check"
checked_string = "uncheck"

print "You can {} that step!".format(checked_string)

Is there a shortcut to this? I was just curious.

print "You can {} that step!".format('check' if checked else 'uncheck')