【问题标题】:What's the recommended way to return a boolean for a collection being non-empty in python?在python中为非空集合返回布尔值的推荐方法是什么?
【发布时间】:2010-09-16 12:35:56
【问题描述】:

我在 SO 上遇到了Python: What is the best way to check if a list is empty? 的问题。

现在,如果我想返回 True (False),具体取决于集合 coll 在函数中是否为非空(空),那么推荐的方法是什么? return not not coll?

【问题讨论】:

    标签: python collections


    【解决方案1】:

    你可以使用

    return bool(coll)
    

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 2016-05-26
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 2019-07-23
      相关资源
      最近更新 更多