繁体   English   中英

python中的多维数组

[英]Multi-dimensional Array in python

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

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

并通过foreach($item as $a => $b)迭代它们

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM