#TUPLE########################### a = (1, 2, 3, 4, 5, "a") # tuple增删查(不支持改) # 增 b = (7, 8) c = a + b d = a.__add__(b) print(c) print(d) # 删 b = a[0:3] + a[4:] print(b) # 查 print(a[0]) #SET######################### b = {9, 8, 7, 6, "fad", "CBD"} ########### 增 b.add(4) b.add(100) ########### 删 # pop删除任意元素,慎用 print("set pop", b.pop()) # remove中得参数必须是元素的值,没有的话报异常 print("set remove", b.remove(9)) # discard元素,没有的话不报异常 b.discard(9) ############改不了 ############查不了 print("set 中是否包含9?", b.__contains__(9)) # DICT dic = {"name": "zhang", "age": 18} #########增 dic.__setitem__("sex", "nan") #########删 dic.pop("name") print(dic) # LIFO dic.popitem() print(dic) #########改 dic.__setitem__("name", "lisi") ##########查 dic.__setitem__("sex", "nan")
#key不存在不会报异常 print(dic.get("sex")) # key不存在可以会报异常 print(dic["sex"]) ###list lis = [1, 2, 3, 4, 5] ##############增加 lis.append(66) ############删除 # Remove first occurrence of value. lis.remove(2) # Remove and return item at index (default last). lis.pop(3) ###########改 lis[1] = 10 lis.__setitem__(2, 11) ###########查 print(lis.__getitem__(3)) print(lis[3])