jeudi 7 novembre 2019

python 3 boolean logic shortcut

I have code that looks something like this:

x = someIntValue
if y is None:
    y = x

elif x < y:
    y = x

Is there a shorter way of doing this? eg, something like: y = x if x < y or not y?

the issue is that y can be None and or a number

Aucun commentaire:

Enregistrer un commentaire