day5 dict嵌套

#!/usr/bin/env python 
# -*- coding:utf-8 -*-

dic = {
    'name': ['alex', 'wusir', 'taibai'],
    'py9': {
        'time': '1213',
        'learn_money': 23700,
        'address': 'CBD',
    },
    'age': 21
}

dic['age'] = 56

dic['name'].append('ritian')
print(dic)

dic['name'][1] = dic['name'][1].upper()
print(dic)

# 在py9中新添加一个 KV对 female : 6
print(dic['py9'])
dic['py9']['female'] = 6
print(dic['py9'])

针对字典中嵌套字典的系列操作

 

补充:习题, 在一串由字母和数字随机组合的字符串里 统计出数字串的个数

info = input('>>>')
for i in info:
    if i.isalpha():
        info = info.replace(i, ' ')
    else:
        pass
print(info)
L = len(info.split())
print(L)

 

posted @ 2019-02-15 17:41  云川望雨  阅读(125)  评论(0编辑  收藏  举报