Set Operations: What will be the output of the following code?

Code

a = {1, 2, 3, 4}
b = {3, 4, 5, 6}
print(a ^ b)
  • {3, 4}
  • {1, 2, 5, 6}
  • {1, 2, 3, 4, 5, 6}
  • Error. Unsupported operand type for set.

a ^ b returns the symmetric difference between a and b, i.e. the set of elements present in either a or b, but not both. 

Comments