>>> def foo(a):
print "called the function"
if(a==1):
return 1
else:
return None
>>> a=1
>>> if(foo(a) != None and foo(a) ==1):
print "asdf"
called the function
called the function
asdf
Hi. how can i avoid calling the function twice without using an extra variable.
foo(a)into a variable. Then check the variable value inif()clause.True, the first has to be. Also note that brackets around the condition are considered bad form in Python.if(a==1):should just beif a==1:.