3.1.1 字典,Key-Value
语法:
info = { 'stu1101':'Cheng', 'stu1211':'Ti', 'stu1324':'Yizi' } print(info) print(info['stu1211']) #查找信息 或者print(info.get('stu1103')) info['stu1101']='程' #修改信息 print(info) info['stu115']='程' #添加信息 print(info) del info['stu1211'] #删除某个信息 或者 info.pop('stu1211') print(info)
3.1.2 字典可以多级嵌套,Key尽量别写中文
3.2.1 集合及其操作
s = set([1,2,3,4,5]) #创建一个数值集合
e = set(["Hello","World"]) #创建一个字符串集合
a = s | e #s和e的并集
b = s & e #s和e的交集
c = s - e #s和e的差集(元素在s中不在e中)
d = s ^ e #s和e的对称差集(所有只在一个集合中出现的元素的集合)
e.add("!") #添加一个元素
s.update([7,8,9]) #添加多个元素
使用remove( )可以删除一项
e.remove("o")