Use the in operator
if num in a :
as in
def test(num):
a = [1, 2, 3]
if num in a :
return True
else :
return False
a work around would be (as suggested by Padraic)
def test(num):
a = [1, 2, 3]
return num in a
This would work because, The in operator compares if the LHS is present in the RHS and returns a boolean value respectively.
Also this is possible
test = lambda x: num in [1, 2, 3]
That is all in a single line!