gpt4 book ai didi

python - 如何在 Python 中检查列表是否为空?

转载 作者:IT老高 更新时间:2023-10-28 21:08:57 27 4
gpt4 key购买 nike

我正在使用的 API 可以返回空的 [] 列表。

以下条件语句未按预期工作:

if myList is not None: #not working
pass

if myList is not []: #not working
pass

什么会起作用?

最佳答案

if not myList:
print "Nothing here"

关于python - 如何在 Python 中检查列表是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1725517/

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