Function Details: ascii

Description


Returns a string containing a printable representation of an object, escaping non-ASCII characters.


Extended Description


The ascii() function returns a string representation of an object, similar to repr(), but escapes the non-ASCII characters in the string with \x, \u or \U escapes. This can be useful when you need a printable representation of an object that contains only ASCII characters.


Read More about ascii from Python Documentation

Function Signature


ascii(object: Any) -> str

Module: builtins

Parameters


This function takes one parameter: object (any Python object). The function will return a string representation of this object.


Parameter List


  • object: Any

Return


Returns a string containing a printable representation of the object, with non-ASCII characters escaped.


Return Type


str

Output

Explanation

This example shows how ascii() handles both ASCII and non-ASCII strings, including Unicode characters.