How to check if the string is empty?

后端 未结 25 1542
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 14:47

Does Python have something like an empty string variable where you can do:

if myString == string.empty:

Regardless, what\'s the most elegan

相关标签:
25条回答
  • 2020-11-22 15:27

    I once wrote something similar to Bartek's answer and javascript inspired:

    def is_not_blank(s):
        return bool(s and s.strip())
    

    Test:

    print is_not_blank("")    # False
    print is_not_blank("   ") # False
    print is_not_blank("ok")  # True
    print is_not_blank(None)  # False
    
    0 讨论(0)
提交回复
热议问题