标签:update enc pop clear date set 创建 子集 迭代
set1 =set({1,2,‘barry‘}) set2 = {1,2,‘barry‘} print(set1,set2)
set1 = {‘alex‘,‘wusir‘,‘ritian‘,‘egon‘,‘barry‘} set1.add(‘17‘) print(set1) #update:迭代着增加 set1.update(‘A‘) print(set1) set1.update(‘老师‘) print(set1) set1.update([1,2,3]) print(set1)
set1 = {‘alex‘,‘wusir‘,‘ritian‘,‘egon‘,‘barry‘} set1.remove(‘alex‘) #删除一个元素 print(set1) set1.pop() #随机删除一个元素 print(set1) set1.clear() #清空集合 print(set1) del set1 #删除集合 print(set1)
set1 = {1,2,3,4,5} set2 = {4,5,7,8,9} print(set1 & set2) print(set1.intersection(set2))
print(set1 | set2) print(set1.union(set2))
print(set1 ^ set2) print(set1.symmetric_difference(set2))
print(set1 < set2) print(set1.issubset(set2)) print(set2 > set1) print(set2.issuperset(set1)) s = frozenset(‘barry‘) print(s,type(s))
标签:update enc pop clear date set 创建 子集 迭代
原文地址:https://www.cnblogs.com/BZMYA/p/9397809.html