1

Is there any logic behind it?

>>>'a' and 'b' and 'c'
'c'
>>>'a' or 'b' or 'c'
'a'
mhawke
  • 84,695
  • 9
  • 117
  • 138
vinay kumar
  • 583
  • 6
  • 18

1 Answers1

8

Yes, there is logic, Boolean logic.

Boolean operators in Python are lazy, so they return the first value that proves that the entire statement is True.

'a' and 'b' and 'c' returns c because it's the first time it can prove the whole statement is True.

'a' or 'b' or 'c' returns a because it's True, so the rest of the values in the statement don't matter.

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67