+ 1

Bitwise XOR between these sets returns "set()": Why?

a = {0, 1} b = {1, 0} print(a ^ b) # prints "set()"

26th Nov 2020, 2:55 PM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar
4 Answers
+ 3
Md. Niamul Ahad Chowdhury ^ operator only includes the unique items from the sets, the items from set a, which don't exists in set b and the items from set b, which don't exist in set a. All items in set a exist in set b and viceverca, so the combined set became empty.
26th Nov 2020, 5:39 PM
Seb TheS
Seb TheS - avatar
+ 2
If it printed { }, you could not conclude from the output, whether the printed object was an empty dict or empty set, maybe that's why empty sets are represented as set().
26th Nov 2020, 3:02 PM
Seb TheS
Seb TheS - avatar
+ 1
Seb TheS Yes, this is the answer I was hoping for. Thanks.
26th Nov 2020, 6:13 PM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar
0
Seb TheS Okay, thank you. But why was it empty in the first place?
26th Nov 2020, 4:20 PM
Md. Niamul Ahad Chowdhury
Md. Niamul Ahad Chowdhury - avatar