dict.md 1.2 KB
Newer Older
F
feilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# Python 字典

字典的基本使用,插入key-value,并打印结果

```python
if __name__ == '__main__':
    map = {}
    map['name'] = "monkey"
    map['age'] = 25
    map['tags'] = "猴子"
    map['tags'] = ['程序员', '户外达人']
    map['profile'] = {'info1': "test", "info2": "test"}

    print(map['tags'])
    print(map['profile'].get("info3"))
```

上述代码的打印结果是?

## template

```python
if __name__ == '__main__':
    map = {}
    print('* 初始化字典:', map)

    print('* 使用下标插入数据到字典')
    map['name'] = "monkey"
    map['age'] = 25
    map['no'] = 10000

    for key in map:
        value = map[key]
        print("{}:{}".format(key, value))

    print('* 字典里可以插入其他数据类型,例如插入列表')
    map['tags'] = ['程序员', '户外达人']
    print('* 打印 tags :{}', map.get('tags'))
    print('* 字典里可以插入其他数据类型,例如插入字典')
    map['profile'] = {'info1': "test", "info2": "test"}
    print('* 打印 profile :{', map.get('profile'))
```

## 答案

```python
['程序员', '户外达人']
None
```

## 选项

### A

```python
猴子
None
```

### B

```python
猴子
test
```

### C

```python
['程序员', '户外达人']
test
```