dimanche 22 février 2015

How to have condition inside a string generation line of code in Python

I am trying to achieve this:


myString = "%s" % ("banana" if myDict['fruit] not 'None' else: "NOT a banana")


I would like to keep this optimised and do the logic while generating the string. What would be the correct syntax to perform a logic inside a string generator.


Aucun commentaire:

Enregistrer un commentaire