0

I have a recursive function called eval() that in one case returns:

 base case: ...

 if some_case():
        return eval() and eval() 

That was my first attempt, which did not return the expected result. unlike what I believe to be that an equivalent code:

 if base case():
     ...

 if some_case():     
    add_first = eval()
    add_second = eval()
    return add_first and add_second 

which seemed to to the trick.

Would like an explanation on the difference. any ideas?

Bar_C
  • 1
  • 2
  • 1
    Don't call it `eval`, since that's a builtin Python function. But to answer your question, the `and` operator will not evaluate its second operand if the first operand evaluates to false. – Tom Karzes Oct 28 '17 at 10:04
  • Sounds like a shortcut evaluation problem. btw isn't `eval()` a builtin function? – quamrana Oct 28 '17 at 10:04
  • @TomKarzes your right ,the eval was just for the code example :) – Bar_C Oct 28 '17 at 12:17
  • @quamrana indeed that answers it as well, thank you! – Bar_C Oct 28 '17 at 12:18

0 Answers0