+ 9

x and y ;x or y in python

how does and ,or operator work in python 3. 2 and 3 outputs 3. 3 and 2 outputs 2. 2 or 3 outputs 2. 3 or 2 outputs 3. what is happening??why??

23rd Dec 2018, 3:12 PM
Saksham Jain
Saksham Jain - avatar
3 ответов
+ 15
You input numbers, which all evaluate to True if they're not zero. Expressions with 'and' or 'or' return the last value checked. And the checking stops as soon as a result is found (in your case always True). 'Or' asserts that only one of the given values is True, so in the 'or' phrases already the first number is returned. 'and' phrases need to make sure that ALL values are True, so you get the second value in your examples.
23rd Dec 2018, 3:18 PM
HonFu
HonFu - avatar
+ 2
Truth table for AND operator: A B Output T F False T T True F T False F F False Truth table for OR Operator A B Output T T True T F True F T True F F False T stands for True and F stands for False.. Just take a look at this you will get some idea..
24th Dec 2018, 2:39 PM
Dilji
Dilji - avatar
+ 2
In AND operation if 1st variable is true then only it will check for 2nd one .....if 1st variable only false I give direct output false
21st Mar 2019, 2:33 AM
Girish K S
Girish K S - avatar