ascii gives diagnostic text an ASCII-only representation. Escapes in the result describe the characters and do not change the source string.
Worked example
print(ascii('café'))Result
'caf\xe9'Implementation notes
A representation intended for a log is rarely appropriate for a customer label. Store the original value and apply escaping only in the diagnostic output.
Try it yourself
Compare print(value), repr(value) and ascii(value) for an accented label.
Open the Python example →Editorial date December 20, 2025 · Published December 6, 2026