首页 > 解决方案 > python中的多维数组

问题描述

在 php 中,我们可以创建多维关联数组,例如

 $item = array(
     "spec" => array(
        "more" => "smth"
    ))   

并遍历它们foreach($item as $a => $b)

我想知道我是否可以做同样的事情,包括 python 中的迭代过程

标签: pythonpython-3.x

解决方案


是的,您可以使用这样的字典(字典)(python 3):

item = {"spec": {"more": "smth"}}

for key, value in item.items():
    print("The key was '" + key + "' and the value was:")
    print(value)

推荐阅读