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

前端 未结 11 480
鱼传尺愫
鱼传尺愫 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条回答
  •  猫巷女王i
    2021-01-30 12:54

    Either is fine, though None is more common as a convention - None indicates that no value was passed for the optional parameter.

    There will be times when "" is the correct default value to use - in my experience, those times occur less often.

提交回复
热议问题