# 列表 [ ] 索引取值:取下不取上 # 可重复 list_1 = [1,2,3 ]list_2 = [ " 蟹老板 " , " 章鱼哥 " , " 海绵宝宝 " ,True,list_1, " 蟹老板 " ] print (list_2) print (list_2) # 有序 print (list_2[0]) print (list_2[2 ]) p
# 列表 [ ] 索引取值:取下不取上
# 可重复
list_1 = [1,2,3] list_2 = ["蟹老板","章鱼哥","海绵宝宝",True,list_1,"蟹老板"] print(list_2) print(list_2) # 有序 print(list_2[0]) print(list_2[2]) print(list_2[-1]) print(list_2[0:4]) print(list_2[:-3]) print(list_2[2:]) print(list_2[:]) print("=============") print(list_2[-2][1]) # 取两层列表的值 # 获取长度 list_len = len(list_2) print(list_len) # 取最后一个值 -- 通过长度 print(list_2[list_len - 1]) # 添加值 list_2.append("蛋清") # 插入 list_2.insert(1,"蛋黄") print(list_2) # 修改值 list_2[3] = False print(list_2) # 删除值 list_2.remove(list_1) list_2.remove("蟹老板") print(list_2) # 删除所有 # list_2.clear() # print(list_2) # --> [] list_3 = ["尤加利","露莲"] print(list_2 + list_3) print(list_3 + list_2) print(list_3*2)
# 字典 {} 键名一般为字符串,且不能重复
DongDong = {"name":"东东","age":28,"height":188,"sex":"男","mood":"happy"} # 无序 print(DongDong) print(DongDong) # 读取数据 print(DongDong["height"]) print(DongDong.get("height")) # 修改数据 DongDong["name"] = "大东" print(DongDong) # 增加数据 -- 键值对 DongDong["study"] = "Java" print(DongDong) # 获取字典的长度 print(len(DongDong)) # 字典组合 NianNian ={"who":"念念","like":"shutterbug"} DongDong.update(NianNian) print(DongDong)