TypeError:^:“list”和“list”的操作数类型不受支持

2024-06-30 16:20:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在读Learning Python by Mark Lutz。 它写在Python表达式运算符一章中:

x ^ y - Bitwise XOR, set symmetric difference

brief googling主题之后,symmetric difference我期望{}作为输出:

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

但是我得到了:

^{pr2}$

我没有得到什么?^实际上是为了什么?在


Tags: 主题by表达式运算符learningmarkprintset
1条回答
网友
1楼 · 发布于 2024-06-30 16:20:50

正如文档所说,它是set-symmetric difference,python使用set对象来演示支持所有set操作的集合。在

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

相关问题 更多 >