dimanche 9 août 2015

using else in inline conditional python

I know I can do this:

z = a if switch == 1 else z = b

but what if I want z=a if switch=1, z=b if switch=2, and z=c if switch=3? Is there a python valid way to write this as a single line?

something like:

z = a if switch == 1 else z = b if switch == 2 else z = c

Thanks, just learning Python now (obviously).

Aucun commentaire:

Enregistrer un commentaire