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 fxc3xbcr"
Wie geht's dir für
你好呀
b'xe4xbdxa0xe5xa5xbdxe5x91x80'
你好呀

utf-8和unicode的区别

原文地址:https://www.cnblogs.com/cydcyd/p/13888619.html