python3基础2
# 列表(list、数组)、元组、字典 list_ = ["a", "c", 1, 2] print(list_) # list_.append("c") # 末尾追加 # list_[2] = "cc" # 替换/修改 # list_.insert(1, "b") # 插入 list_.remove("c") # 删除 print(list_) print("===============================元组===") tuple_ = ("a", "b", "c", 1, 2) print(tuple_[0:-2]) # 取范围 # del tuple_ # 删除整个元组 print(tuple_[0]) print("===============================字典===") dict_ = {"key":"value", "name":"tom", "age": 29} for k, v in dict_.items(): print(k) print(v) print(dict_.keys()) # 取到所有的key print(dict_.values()) # 取到所有的value # dict_["hello"] = "world" # 添加 # dict_["key"] = "vvvv" # 替换/修改 del dict_["key"] print(dict_) ll = [ ["a", "b", "c"], [1, 2, 3], ] print(ll[1][2]) ld = [ {"name": ("tom", "jack"), {"age": 29}, ] dl = {"name":["tom", "jack", "blue"], "age": [22, 27, 31]} print(ld[1]["age"]) print(dl["name"][1])
本文来自博客园,作者:Harry_666,转载请注明原文链接:https://www.cnblogs.com/harry66/p/12041860.html