How does the logical `and` operator work with integers?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: The World Wide Mind
--
Chapters
00:00 How Does The Logical `And` Operator Work With Integers?
00:33 Accepted Answer Score 35
00:59 Answer 2 Score 13
01:14 Thank you
--
Full question
https://stackoverflow.com/questions/4965...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python
#avk47
    Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: The World Wide Mind
--
Chapters
00:00 How Does The Logical `And` Operator Work With Integers?
00:33 Accepted Answer Score 35
00:59 Answer 2 Score 13
01:14 Thank you
--
Full question
https://stackoverflow.com/questions/4965...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python
#avk47
ACCEPTED ANSWER
Score 35
From the Python documentation:
The expression
x and yfirst evaluatesx; ifxis false, its value is returned; otherwise,yis evaluated and the resulting value is returned.
Which is exactly what your experiment shows happening. All of your x values are true, so the y value is returned.
ANSWER 2
Score 13
It's for every item in Python, it's not dependent on the integer.
not x   Returns True if x is False, False otherwise
x and y Returns x if x is False, y otherwise
x or y  Returns y if x is False, x otherwise
1 is True, so it will return 2