gpt4 book ai didi

python - 如果 Dict 值为 null

转载 作者:太空狗 更新时间:2023-10-30 01:44:48 24 4
gpt4 key购买 nike

In [54]: User
Out[54]: {0: {'uid': ' rpatil\n'}, 1: {}}

In [55]: User[0]
Out[55]: {'uid': ' rpatil\n'}

In [56]: User[1]
Out[56]: {}

In [57]: if User[1] == '':
....: print 'Null'
....:

In [58]:

那么如何检查多字典中的Value是否为Null

我试过点击链接但没有用 None value in python dictionary

最佳答案

空字典是假的。只需使用 if not dic

>>> testDict = {}
>>> if not testDict:
print "Empty"


Empty

因此,在您的代码中。

>>> User = {0: {'uid': ' rpatil\n'}, 1: {}}
>>> if not User[1]:
print "NULL"


NULL

关于python - 如果 Dict 值为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18964842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com