Python: most idiomatic way to convert None to empty string?

Probably the shortest would be
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.

Leave a Comment