Py学习  »  Python

在Python3.x中查找数组是否存在且不为空

Captain Nemo • 6 年前 • 2178 次点击  

我想检查json输入中是否存在元素,下面的代码片段似乎可以工作

import json
y = {
    "attributes": [
        {
            "name": "test"
        }
    ]
}

p2 = json.dumps(y)

if 'attributes' not in p2:
    print("not found")
else:
    print("found")

我现在想检查attributes元素是否是list类型和list大小

什么是蟒蛇式的方法来达到这个目的?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44204
文章 [ 4 ]  |  最新文章 6 年前