set集合具有唯一性,无序性,所以没有索引index
frozenset()用来限制集合的修改
1 set1 = frozenset([1, 2, 3, 5]) 2 set2 = {1, 3, 2, 5} 3 print(set1 == set2) 4 # 下面则不可创建集合 5 try: 6 set3 = {[1, 2, 3, 5]} 7 except Exception as e: 8 print(e) 9 try: 10 set1.add(4) # set1不可变更 11 except Exception as e1: 12 print(e1) 13 set2.add(8) 14 set2.remove(3) 15 print(set2) 16 # 集合的唯一性 17 set4 = {1, 1.0} 18 print(set4)