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])

 

 

posted @ 2019-12-15 08:33  Harry_666  阅读(224)  评论(0编辑  收藏  举报