Python encoding (encode) decoding (decode) problem

s = 'hurried' 
print(s)
s1 = s.decode( "utf-8") # utf-8 is converted to Unicode, decode (decoding) needs to indicate the current encoding format
print(s1 , type(s1))

s2 = s1.encode( "gbk") # unicode is converted to gbk, encode(encoding) needs to indicate the generated encoding format
print(s2 , type(s2))

s3 = s1.encode( "utf-8") # unicode is converted into utf-8, encode (encoding) indicates the generated encoding format
print(s3 , type(s3))

 

 

s = u'127.0.0.1' # unicode encoding 

s1 = s.encode( "utf-8") # convert unicode encoding to utf-8

s2 = s.decode( "utf-8") # convert unicode decoding to utf-8

print s1
print s2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325247609&siteId=291194637