python encode decode

 1 str = "Wie geht's dir für"
 2 print(str)
 3 str2 = str.encode(encoding='UTF-8')
 4 print(str2)
 5 str3 = str2.decode(encoding='UTF-8')
 6 print(str3)
 7 
 8 str = "你好呀"
 9 print(str)
10 str2 = str.encode(encoding='UTF-8')
11 print(str2)
12 str3 = str2.decode(encoding='UTF-8')
13 print(str3)

输出结果

Wie geht's dir für
b"Wie geht's dir f\xc3\xbcr"
Wie geht's dir für
你好呀
b'\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x91\x80'
你好呀

 

utf-8和unicode的区别

posted @ 2020-10-28 00:18  cydcyd  阅读(44)  评论(0编辑  收藏  举报