>>> 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
こんにちは。 私は余分な変数を使用せずに関数を2回呼び出すことを避けることができます。条件付きのPythonと "and"
'を変数に変換します。次に、 'if()'節で変数の値をチェックします。 – Raptor
if(foo(a)== 1): – jimifiki
正確には、第2の条件が「真」であるためには、第1の条件が成立する必要があります。また、条件のまわりの括弧は、Pythonでは悪い書式とみなされます。 'if(a == 1):'は 'a == 1:'ならば ''でなければなりません。 –