Built-in Functions and Types
ascii()
Produce a representation with non-ASCII characters escaped using backslash sequences. It starts from repr-like output and replaces non-ASCII code points, making the representation useful in ASCII-only diagnostic contexts. It does not transliterate words, encode text to bytes or remove accents. Custom __repr__() failures can propagate.
Formal Syntax & Structure
python syntaxpython
ascii(object, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| object | object | Value to represent; positional only. |
Return Value
str
ASCII-only representation, with non-ASCII code points escaped.
Working Example
Example Snippetpython
print(ascii("café"))print(ascii("سلام"))print(ascii("🙂"))