Python程序教程

您现在的位置是:首页 >  Python

当前栏目

Python set() 函数

Python,set,函数
2025-04-07 09:01:23 时间

大家好,又见面了,我是你们的朋友全栈君。

测试示例:

>>>x = set('runoob')
>>> y = set('google')
>>> x, y
(set(['b', 'r', 'u', 'o', 'n']), set(['e', 'o', 'g', 'l']))   # 重复的被删除
>>> x & y         # 交集
set(['o'])
>>> x | y         # 并集
set(['b', 'e', 'g', 'l', 'o', 'n', 'r', 'u'])
>>> x - y         # 差集
set(['r', 'b', 'u', 'n'])
>>>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155907.html原文链接:https://javaforall.cn