Discuss / Python / not_empty(s)函数有点不明白

not_empty(s)函数有点不明白

Topic source

贝司特曼

#1 Created at ... [Delete] [Delete and Lock User]
def not_empty(s):
    return s and s.strip()

单独测试的情况下,函数返回的不是布尔值,为什么能做筛选呢?

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

Python把None, 0, ''当作布尔的False,其他都是True


  • 1

Reply