ITeye博客

Python set

fairy_xzc · 2016-09-29 08:55 · Python · 编程语言 · Markdown

原创装载请注明出处:http://agilestyle.iteye.com/blog/2327559

 

set.py

l = [1, 3, 2, 1, 2, 3]
print(l)
s = set(l)
print(s)

# add(key)方法可以添加元素到set中,可以重复添加,但不会有效果
s.add(4)
print(s)

# remove(key)方法可以删除元素
s.remove(4)
print(s)

s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
# {2, 3}
print(s1 & s2)
# {1, 2, 3, 4}
print(s1 | s2)

 

Console Output

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。