我正在使用Python 2.7.3版本,有人可以解释一下以下字面值之间的区别吗:
'\u0391'
并且:
u'\u0391'
以下是它们在 REPL 中的不同回显方式(特别是添加到 a1 的额外斜杠):
>>> a1='\u0391'
>>> a1
'\\u0391'
>>> type(a1)
<type 'str'>
>>>
>>> a2=u'\u0391'
>>> a2
u'\u0391'
>>> type(a2)
<type 'unicode'>
>>>
str
,因为str
现在是Unicode(但是b'\u0391'
仍然等同于您的a1
,只不过它是bytes
类型)。 - abarnert