python3基础2

Posted Huny

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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])

 

以上是关于python3基础2的主要内容,如果未能解决你的问题,请参考以下文章

0基础学python3心得体会 - python3学习笔记 - python3基础

Python基础--Python3基础语法

Python3基础

python3基础学习笔记(基础知识)-01

python能做啥有趣的东西

Python3基础教程资料