Python: Convert to String
Convert value to string type
repr(x)
-
Convert to a string form that can be read back into Python or for
eval()
xx = [3, 4.3, (7, 8, "9")] print(repr(xx) == "[3, 4.3, (7, 8, '9')]")
str(x)
-
Convert to string in a human readable form.
Note: in practice,
str
andrepr
returns the same thing.xx = [3, 4.3, (7, 8, "9")] print(str(xx) == "[3, 4.3, (7, 8, '9')]")
for more flexible way, use the format
method.
〔see Python: Format String〕
Python, String
- Python: Quote String
- Python: Triple Quote String
- Python: Raw String
- Python: f-String (Format, Template)
- Python: String Escape Sequence
- Python: Unicode Escape Sequence
- Python: Print String
- Python: Print Without Newline
- Python: Convert to String
- Python: Join String
- Python: Format String
- Python: String Methods
- Python: Search Substring
- Python: Split String
- Python: String, Check Case, Char Class
- Python: Letter Case Conversion
- Python: Unicode 🐍
- Python 2: Unicode Tutorial