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.
More Related Contents:
- Find string between two substrings [duplicate]
- Repeat string to certain length
- What does += mean in this context?
- How to convert a string in the desired manner?
- Why does comparing strings using either ‘==’ or ‘is’ sometimes produce a different result?
- How to search and replace text in a file?
- Convert JSON string to dict using Python
- Print string to text file
- Get the key corresponding to the minimum value within a dictionary
- How can I do multiple substitutions using regex?
- How to generate a random string of a fixed length in Go?
- How to match any string from a list of strings in regular expressions in python?
- Extract email sub-strings from large document
- Math operations from string [duplicate]
- Does Python do slice-by-reference on strings?
- Safely evaluate simple string equation
- Strip spaces/tabs/newlines – python
- Finding the ranking of a word (permutations) with duplicate letters
- How to generate random strings in Python?
- Extract numeric part of strings of mixed numbers and characters in R
- Convert list of strings to dictionary
- How do I check if raw input is integer in python 2.7?
- Use character string as function argument
- Sort list of strings by a part of the string
- Python Remove Comma In Dollar Amount
- Any method equivalent to PadLeft/PadRight?
- Delete certain lines in a txt file via a batch file
- Convert time.Time to string
- How to replace whitespaces with underscore?
- How do I verify that a string only contains letters, numbers, underscores and dashes? [duplicate]