Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between encode/decode in Python 2/3

In Python 3, we use "string".encode() and "string".decode() to convert an Unicode string to a bytes string, or convert a bytes string to an Unicode string.

In Python 2, we have str() and unicode(), we can encode() and decode() to them, too. But, is there any difference between Python 3?

like image 695
比尔盖子 Avatar asked Mar 09 '26 12:03

比尔盖子


1 Answers

In python2, str is byte strings, unicode is unicode string. But some silly thing for encode and decode, details refer to http://nedbatchelder.com/text/unipain.html

like image 72
linbo Avatar answered Mar 12 '26 02:03

linbo