+ 2

Difference between bitwise & , boolean operator AND in python

17th Apr 2018, 6:28 PM
sweta t
sweta t - avatar
2 Answers
+ 5
The & operator is equivalent to the intersection() operation, and creates a new set with elements common to a and b a = set([1, 2, 3]) b = set([3, 4, 5]) print(a & b) #->3 && is used to compare two values a=True && False a is false e.t.c
17th Apr 2018, 7:39 PM
᠌᠌Code X
᠌᠌Code X - avatar
Just to add to Brain's excellent answer... I made this for demonstration for you (although it's a work in progress) https://code.sololearn.com/W26dgSxWvWCQ/#htm It demonstrates a binary AND operation, in an interactive way. This will also be how python acts with this operation. I also created this demonstration in python: https://code.sololearn.com/cGJ7gRt0ix2J/#py Any questions, please let me know. I will do my best to answer further. Good luck :-)
18th Apr 2018, 1:02 AM