Initialize a string variable in Python: “” or None?

前端 未结 11 461
鱼传尺愫
鱼传尺愫 2021-01-30 12:44

Suppose I have a class with a string instance attribute. Should I initialize this attribute with \"\" value or None? Is either

11条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 12:52

    empty_string = ""
    
    if not empty_string:
    
        print "Empty string is not set"
    

    =>Empty string is not set

    if empty_string is not None:
        print "Empty string is not None"
    

    =>Empty string is not None

提交回复
热议问题