集合
#集合 可变数据类型,但是存储的元素必须是可变数据类型,无序,不重复! set1 = set({1,2,3}) #set2 = set(1,2,[2,4],{2,4}) # 错的,必须放可哈希的 print(set1) print(set2)
增
#集合的添加 set1 = set({'suidyai','kjsadfhik','ldsahf'}) set1.add('套你大象') print(set1) set2 = {'sdjka','jaksahd'} set2.update('套你大象') print(set2)
删
#集合的删除 set1 = {'sakdhi','sadhk','sladjsa'} set1.pop()#随机删除 print(set1.pop())#1有返回值 print(set1)
set1 = {'sakdhi','sadhk','sladjsa'} # set1.pop()#随机删除 # print(set1.pop())#1有返回值 # print(set1) set1.remove('sakdhi')#按元素去删除 print(set1)
查
#查 set1 = {'sakdhi','sadhk','sladjsa'} for i in set1: print(i)