What is the most idiomatic way to do the following?
def xstr(s): if s is None: return \'\' else: return s s = xstr(a) + xstr(b)
Probably the shortest would be str(s or '')
str(s or '')
Because None is False, and "x or y" returns y if x is false. See Boolean Operators for a detailed explanation. It's short, but not very explicit.