python ascii()函数详细教程
ascii()
函数接受一个对象参数,返回该对象的字符串形式,如果返回的字符串中包含非ASCII编码的字符,会使用\x
、\u
和\U
来进行转义;
>>> ascii(['你','好'])
"['\\u4f60', '\\u597d']"
>>> ascii({1:111,2:222})
'{1: 111, 2: 222}'
>>> ascii('hello world')
"'hello world'"
class test:
def __init__(self):
pass
def __str__(self):
return 'hello world'
print(ascii(test))
A = test()
print(ascii(A))
print(A)
输出:
<class '__main__.test'> <__main__.test object at 0x0000027DC6261370> hello world
如需转载,请注明出处;本文地址:https://www.perfcode.com/p/python-ascii-function.html