[Tutor] Question about equality of sets

Jim Byrnes jf_byrnes at comcast.net
Sat Apr 5 19:46:19 CEST 2014


Ubuntu 12.04 python 3.3

I was working through an exercise about sets. I needed to find the 
duplicates in a list and put them in a set.  I figured the solution had 
to do with sets not supporting duplicates.  I finally figured it out but 
along the way I was experimenting in idle and got some results I don't 
understand.

 >>> s = {1,2,3}
 >>> s
{1, 2, 3}
 >>> s.add(1) == s    # <1>
False
 >>> s.add(1) == s.add(2)    # <2>
True
 >>>

Neither <1> or <2> changes s, so why is <1> False and <2> True ?

Thanks,  Jim



More information about the Tutor mailing list