How to check whether a str(variable) is empty or not?

后端 未结 11 2389
北恋
北恋 2020-12-23 18:27

How do I make a:

if str(variable) == [contains text]:

condition?

(or something, because I am pretty sure that what I just wrote is

11条回答
  •  执念已碎
    2020-12-23 19:06

    Some time we have more spaces in between quotes, then use this approach

    a = "   "
    >>> bool(a)
    True
    >>> bool(a.strip())
    False
    
    if not a.strip():
        print("String is empty")
    else:
        print("String is not empty")
    

提交回复
热议问题