1. 程式人生 > >Python 字典的巢狀

Python 字典的巢狀

wf = {
    "name":"汪峰",
    "age":52,
    "hobby":["唱歌", "上頭條", "穿皮褲"],
    "wife": {
        "name": "章子怡",
        "age": 49,
        "hobby":["演戲", "上電視", "當導師"],
        "tishen": {
            "name":"萌萌",
            "age":28
        },
        "zhuli":{
           "name":"磊磊",
           "age": 20
        }

    },
    "zhuli":{
        "name":"寶寶",
        "age":23,
        "hobby":["抽菸","喝酒","燙頭"]
    }
}
print(wf["wife"]["tishen"]["name"])
print(wf["wife"]["hobby"][1])
print(wf["zhuli"]["hobby"][2])

wf["zhuli"]["age"] +=10
print(wf["zhuli"]["age"])

wf["wife"]["hobby"].append("導戲")
print(wf["wife"]["hobby"])

wf["zhuli"]["hobby"].remove("抽菸")
print(wf["zhuli"]["hobby"])