Python ascii() 函数

2024年9月26日 | 1 分钟阅读

python ascii() 函数返回一个字符串,其中包含对象的可打印表示形式,并使用 \x、\u 或 \U 转义字符串中的非 ASCII 字符。

签名

参数

object: 它接受一个对象,如字符串、列表等。

返回

它返回一个对象的可读版本,并将非 ascii 字符替换为转义字符。

Python ascii() 函数示例 1

让我们看看 ascii() 如何处理列表?

输出

'Python is interesting'
'Pyth\xf6n is interesting'
Pyth�n is interesting

解释: 在上面的示例中,变量(例如 normalText 和 otherText)包含字符串值,并返回特定变量的 ascii 值。


下一个主题Python 函数