1 #Author : Kelvin 2 #Date : 2019/1/5 13:20 3 4 #set集合的创建(创建后可修改) 5 li=["kelvin",1,2,"zhangsan","kelvin"] 6 s=set(li) 7 print(s) 8 #运行结果:{1, 2, 'kelvin', 'zhangsan'} 9 10 #frozenset集合的创建(创建后不可修改 )11 s1=frozenset(li)12 print(s1)13 #运行结果:frozenset({1, 2, 'kelvin', 'zhangsan'})14 15 #集合的添加16 s.add("bob")17 print(s)18 #运行结果:{1, 2, 'zhangsan', 'bob', 'kelvin'}19 20 #集合的更新21 s.update("vbcv")22 print(s)23 #运行结果:{'v', 1, 2, 'zhangsan', 'bob', 'kelvin', 'b', 'c'}24 25 s.remove("v")26 print(s)27 #运行结果:{1, 2, 'bob', 'b', 'zhangsan', 'kelvin', 'c'}28 29 s.pop()30 print(s)31 #运行结果:{1, 2, 'zhangsan', 'b', 'c', 'bob'}32 33 s.clear()34 print(s)35 #运行结果:set()36 37 del s38 print(s)39 #运行结果:报错 NameError: name 's' is not defined40 41 # 集合in not in42 li2=[1,2,3]43 print(1 in li2)44 print("elvin" not in li2)45 46 #集合== < > !=47 print(set("kelvin")==set("kelvinelvin")) #True48 49 print(set("kelvin")