Python: what is the operation that returns 6 for the expression (2 and 2*3)?
python
Solution
From the Python language reference:
Note that neither `and` nor `or` restrict the value and type they return to False and True, but rather return the last evaluated argument.
As such, `2 and 2*3` means it first evaluates `bool(2)`, which evaluates to `True`, and then it evaluates `bool(2*3)` which evaluates to `True`. Therefore it'll return the last evaluated argument, which is `2*3` (`6`).
Problem
My first question is what is the more abstract question for the question: 'what is the operation that returns 6 for the expression `(2 and 2*3)`? Please feel free to retitle my question appropriately. My second question is what is it that is going on in python that returns 6 for `(2 and 2*3)`. There seems something elegant going on here, and I'd like to read up on this operation.