mardi 31 mars 2015

Compare to multiple values in an if statement.

im going to need multiple if statements comparing to the same couple elements, and was wondering if there was something along these lines i could do to make the code cleaner and easier.


Example would be that this function.



def test(num):

a = [1, 2, 3]

if num == a :
return True

else :
return False


would return



>>>test(1)
True
>>>test(2)
True
>>>test(5)
False


Instead of having to write the separate if statements for 1, 2, and 3.


Aucun commentaire:

Enregistrer un commentaire