0

Could someone explain the following?

>>> a = {1}
>>> b = {2}
>>> a & b == set()
True
>>> a & b == {}
False

Why is this choice made?

Dimitris Leventeas
  • 1,622
  • 2
  • 16
  • 29
  • 1
    @skyl Set literals were added ~2.7 I believe. Edit: Yup, it's [a 3.1 feature backported into 2.7](http://docs.python.org/dev/whatsnew/2.7.html#python-3-1-features) as it's a non-breaking change. – Gareth Latty May 05 '12 at 19:15

1 Answers1

5

Your code a & b == {} is comparing a ANDed with b with {}, an empty dictionary. So, the result of the and and an empty dictionary are different and the result is false.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
mata
  • 67,110
  • 10
  • 163
  • 162