Reputation: 1012
The fooliwng code:
def foo(arg):
return arg==arg[::-1]
if __name__ == '__main__':
print (foo(['A', 'V', 'I', 'V', 'A']) or foo(['A', 'B', 'C', 'D']) and foo([1, 2, 3, 1]))
will print True
- why?
why the behavior is like:
print (foo(['A', 'V', 'I', 'V', 'A']) or (foo(['A', 'B', 'C', 'D']) and foo([1, 2, 3, 1])))
And not like:
print ((foo(['A', 'V', 'I', 'V', 'A']) or foo(['A', 'B', 'C', 'D'])) and foo([1, 2, 3, 1]))
Upvotes: 0
Views: 449
Reputation: 109
This is because AND
operator has higher precedence than OR
, check python documentation.
Upvotes: 1