1. 字典;
# # 1. 基本结构
info={
"k1":"v1", # 键值对的形式
"k2":"v2"
}
# # 2. 值可以为任何数据类型
info={
"k1":18,
"k2":True,
"k3":[
11,
22,
{
"k1":"v1",
"k2":"v2",
"k3":(1,"2"),
}
],
"k4":(11,22,33,44)
}
print(info)
# 3. 列表,字典不能作为字典的key
info={
1:"sdd",
"k":"ddd",
True:"ll", # True默认为1,字典的key不能重复
#[1,2]:"ss" # 会报错
(1,2):"kk",
#{1:2}:"pp" #会报错
}
# 4. 字典是无序的,每次输出结果都不一样
# 5. 取值
info={
"k1":18,
"k2":True,
"k3":[
11,
22,
{
"k1":"v1",
"k2":"v2",
"k3":(1,"2"),
}
],
"k4":(11,22,33,44)
}
# 取值为1的元素
v=info["k3"][2]["k3"][0]
print(v)