Python内置函数(4)——ascii

英文文档:

ascii(object)

    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.

说明:

    1. 返回一个可打印的对象字符串方式表示,如果是非ascii字符就会输出x,u或U等字符来表示。与python2版本里的repr()是等效的函数。

>>> ascii(1)
'1'
>>> ascii('&')
"'&'"
>>> ascii(9000000)
'9000000'
>>> ascii('中文') #非ascii字符
"'\u4e2d\u6587'"

作者:〖十月狐狸〗

出处:http://www.cnblogs.com/sesshoumaru/

欢迎任何形式的转载,但请务必注明出处。

本人水平有限,如果文章和代码有表述不当之处,还请不吝赐教。

原文地址:https://www.cnblogs.com/sesshoumaru/p/5976913.html