\'Hello \' + (\'there\' if name is None else name)
Is the equivalent of
msg = \'Hello \' if name is None: msg += \'there\' else:
You could also do this:
msg= 'Hello ' + {name is None: 'there', name == 'Mr Anderson': 'Neo'}.get(True, name)
So either of name is None or name == 'Mr Anderson' is True, or none of them is True, then name will be used.
name is None
name == 'Mr Anderson'
True
name