Something my string var is equal to None.
I don’t want to have if statements to verify the value. Is there any simple way (like str(my_var)) which will return string value if this is not None and '' if None?
Something my string var is equal to None . I don’t want to have
Share
You can use
foo or '', but in casefoois any other falsy value (0, an empty list, etc.) it will result in an empty string, too.Another way would be
'' if foo is None else foo