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)
If you know that the value will always either be a string or None:
xstr = lambda s: s or "" print xstr("a") + xstr("b") # -> 'ab' print xstr("a") + xstr(None) # -> 'a' print xstr(None) + xstr("b") # -> 'b' print xstr(None) + xstr(None) # -> ''