码迷,mamicode.com
首页 > 编程语言 > 详细

python3基础2

时间:2019-12-15 11:05:00      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:for   基础   list   append   end   nbsp   tuple   key   world   

# 列表(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])

 

python3基础2

标签:for   基础   list   append   end   nbsp   tuple   key   world   

原文地址:https://www.cnblogs.com/hy546880109/p/12041860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!