mardi 9 avril 2019

Can we add 'OR' operator along with if and else in Python?

In python, I'm doing a basic check if the object contains a key and getting data from it. But can we add or and check if obj1 does not contain data then check for obj2 and if not then return as None

I have tried as shown. Can I add or operator to this?

int(obj1.amt) if obj1.amt else None

Can we try to check if obj1.amt is None then check obj1.new_amt has value and return that, else return None

Aucun commentaire:

Enregistrer un commentaire