python3转义编码

 

s = 'dy电影'
print(s)  # dy电影
print(type(s))  # <class 'str'>
print(s.encode('utf-8'))  # b'dy\xe7\x94\xb5\xe5\xbd\xb1'
print(s.encode('unicode_escape'))  # b'dy\\u7535\\u5f71'
print(s.encode('unicode_escape').decode('utf-8'))  # dy\u7535\u5f71

s = 'dy\\u7535\\u5f71'
print(s.encode('utf-8'))  # b'dy\\u7535\\u5f71'
print(s.encode('utf-8').decode('unicode_escape'))  # dy电影
print(s.encode('unicode_escape'))  # b'dy\\\\u7535\\\\u5f71'

  

 

posted on 2017-08-30 14:33  蚂蚁flow  阅读(223)  评论(0编辑  收藏  举报

导航