Python内建函数之ascii(object)
Manual
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u or \U escapes. This generates a string similar to that returned by repr() in Python 2.
直译
与repr()类似,返回包含一个可打印表示的对象的字符串,但字符串中的非ASCII(non-ASCII)字符通过使用\x, \u或\U转义符进行转义。生成的字符串与Python 2中的repr()的返回值相近。
实例
>>> ascii(10)
'10'
>>> ascii(900000)
'900000'
>>> ascii('100')
"'100'">>> ascii([0, 1, 2, 3])
'[0, 1, 2, 3]'
>>> ascii('我去年买了个表')
"'\\u6211\\u53bb\\u5e74\\u4e70\\u4e86\\u4e2a\\u8868'"
本文详细介绍了Python内建函数ascii的基本用法,包括如何使用ascii来表示对象,尤其是如何处理非ASCII字符。通过具体实例演示了ascii函数在不同数据类型上的表现,帮助开发者更深入地理解和利用这一功能。
856

被折叠的 条评论
为什么被折叠?



