TypeError: unsupported operand type(s) for ^: 'list' and 'list'

TypeError: unsupported operand type(s) for ^: 'list' and 'list'

我正在阅读Learning Python by Mark Lutz。 它写在 Python Expression Operators chapter:

x ^ y - Bitwise XOR, set symmetric difference

brief googling 主题之后 symmetric difference 我期望 [1, 3] 作为输出来自:

y = ['1', '2']
x = ['2', '3']
print x ^ y  

但我却得到了:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'list' and 'list'

我没有得到什么? ^ 实际上是做什么用的?

正如文档所说,它是集合对称差异,python使用set对象来演示支持所有集合操作的集合。

>>> y = {'1', '2'}
>>> x = {'2', '3'}
>>> 
>>> x ^ y
set(['1', '3'])