decoding the byte code format into another format

Basic byte data type to create:

name = bytes('aike',encoding='utf-8')
print(name)

Output:

b ' Aike '    # begin with b

 

String type Type converted into a byte encode:

name = '艾克'
age = '18'
n = name.encode('utf-8')
a = age.encode('utf-8')
print(n)
print(a)

Output:

B ' \ xe8 \ X89 \ XBE \ xe5 \ X85 \ x8b '     # Chinese output in hexadecimal 
B ' 18 is '

 

The data type byte decoded by decode:

name = '艾克'
age = '18'
n = name.encode('utf-8')
a = age.encode('utf-8')
print(n)
print(a)
nb = n.decode('utf-8')
ab = a.decode('utf-8')
print(nb)
print(ab)

 

 Output:

B ' \ xe8 \ X89 \ XBE \ xe5 \ X85 \ x8b ' 
B ' 18 ' 
Ike
 18

 

Guess you like

Origin www.cnblogs.com/aizhinong/p/11343942.html