How can I closely achieve ?: from C++/C# in Python?

前端 未结 9 1918
滥情空心
滥情空心 2021-02-20 11:02

In C# I could easily write the following:

string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString;

Is there a qu

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-20 11:32

    I also discovered that just using the "or" operator does pretty well. For instance:

    finalString = get_override() or defaultString
    

    If get_override() returns "" or None, it will always use defaultString.

提交回复
热议问题