lundi 21 août 2017

Avoiding if else condition in python

I have two parameter, for example a,b. I have a situation like if both parameters(a,b) can have values or both may not have values or either of the one them have values.

Example:

1st Condition : a=10, b=20

2nd Condition: a=None, b=20

3rd Condition: a=10 , b=None

4th Condition: a=None, b= None

I have to do some operation if value is present and log it. Currently i am doing like below, Is there any efficient way to do this?

if not a:
    print "Value a not present"
if not b:
   print "Value b not present"

# Do operation for A
a = a+1 
# Do operation for B
b = b+1

Aucun commentaire:

Enregistrer un commentaire