1、嵌套的字典
字典还可以包含许多字典,这称为嵌套字典。
例如:
创建一个包含三个词典的字典:
myfamily = {
"child1" : {
"name" : "c",
"year" : 2004
},
"child2" : {
"name" : "java",
"year" : 2007
},
"child3" : {
"name" : "python",
"year" : 2011
}
}
或者,如果想嵌套三个已经作为字典存在的字典:
例如:
创建三个字典,然后创建一个包含其他三个字典的字典:
child1 = {
"name" : "c",
"year" : 2004
}
child2 = {
"name" : "java",
"year" : 2007
}
child3 = {
"name" : "python",
"year" : 2011
}
myfamily = {
"child1" : child1,
"child2" : child2,
"child3" : child3
}
相关文档: