1 模块简介
Python 3中最大的变化之一就是删除了Unicode类型。在Python 2中,有str类型和unicode类型,例如,
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = "blah"
>>> type(x)
>>> y = u"blah"
>>> type(y)
如果我们在Python 3中输入同样的代码,你将会发现,最终返回的都是一个字符串类型。
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = "blah"
>>> type(x)
>>> y = u"blah"
>>> type(y)
Python 3默认的是UTF-8编码。这意味着你可以在字符串或者变量名中使用Unciode字符集。让我们看看实际中是如何运用的。
在Python 2输入如下代码&#