Python: Convert to String

By Xah Lee. Date: .

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 and repr 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