编码:
str = 'Python才是世界上最好的语言'.encode('unicode_escape')
print(str)
输出结果:
b'Python\\u624d\\u662f\\u4e16\\u754c\\u4e0a\\u6700\\u597d\\u7684\\u8bed\\u8a00
解码:
str = 'Python\\u624d\\u662f\\u4e16\\u754c\\u4e0a\\u6700\\u597d\\u7684\\u8bed\\u8a00'
print(str.encode('utf8').decode('unicode_escape'))
输出结果:
Python才是世界上最好的语言