如何在Python中检查列表是否为空? [英] How to check if a list is empty in Python?

查看:193
本文介绍了如何在Python中检查列表是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The API I'm working with can return empty [] lists.

以下条件语句无法按预期运行:

The following conditional statements aren't working as expected:

if myList is not None: #not working
    pass

if myList is not []: #not working
    pass

什么会起作用?

推荐答案

if not myList:
  print "Nothing here"

这篇关于如何在Python中检查列表是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆