开发者

What's the recommended way to return a boolean for a collection being non-empty in python?

开发者 https://www.devze.com 2023-01-16 04:44 出处:网络
I came across the question Python: What is the best way to check if a list is empty? on SO. No开发者_Python百科w if I wanted to return a True (False) depending on whether a collection coll is non-em

I came across the question Python: What is the best way to check if a list is empty? on SO.

No开发者_Python百科w if I wanted to return a True (False) depending on whether a collection coll is non-empty (empty) from a function, what's the recommended way of doing this ? return not not coll ?


You could use

return bool(coll)
0

精彩评论

暂无评论...
验证码 换一张
取 消