字典dict
- 字典是一种组合数据,没有顺序,数据以键值对形式出现
- 字典是无序序列,所以没有分片和索引
- 字典中的每个数据都是键值对(kv对, key-value对)
- key: 必须是可哈希的值,比如int,string,float,tuple, 但是list,set,dict不行
- value: 任何值
创建字典
# 创建空字典
d = {
}
print(type(d))
# 创建空字典2
d = dict()
print(type(d))
d = {
1,2,3}
print(type(d))
d = {
"one":1, "two":2, "three":3}
print(d)
# 用dict创建有内容字典
d = dict({
"one":1