字节字符串和 unicode 字符串输入



我是Python菜鸟。我正在阅读一些文档,我遇到了一些让我感到困惑的事情。

python中的字节字符串和Unicode字符串有什么区别?特别是在输入的内容和输出方面。

请使用最简单的术语进行解释

注意:我使用python 3.x

我四处搜索,发现字节字符串只能包含字节字符,不包括标点符号和其他 unicode 字符。Unicode 字符串可以包含所有 unicode 字符。

在python 2.x中,字节字符串的编写方式与普通字符串非常相似,而Unicode字符串的前缀为"u"。

a = 'foobar'    (byte string)
b = u'foo-bar'    (unicode string)

它在python 3.x中以相反的方式编写

a = b'foobar'    (byte string)
b = 'foo-bar'    (unicode string)

最新更新