我见过Python字典看起来像最近这样:Python字典键/带前缀的值 - 前缀是什么?
test1 = {u'user':u'user1', u'user_name':u'alice'}
这让我困惑了一下,什么是键/值对前u
?它是某种类型的前缀吗?这是如何不同:
test2 = {'user':'user1', 'user_name':'alice'}
我试图玩test1和test2;它们看起来并不相同。有人可以解释前缀是什么吗?
>>> test1 = {u'user':u'user1', u'user_name':u'alice'}
>>> test2 = {'user':'user1', 'user_name':'alice'}
>>> print test1[u'user']
user1
>>> print test1['user']
user1
>>> print test2['user']
user1
>>> print test2[u'user']
'u'手段[unicode的](http://docs.python.org/2/howto/unicode.html)。 – 2013-04-25 20:27:22
[Python的Unicode的(http://docs.python.org/2/howto/unicode.html) – 2013-04-25 20:29:06
当你到数据库,它们将您的字符串转换成Unicode,所以,除非你真正来到这里你处理一个点与unicodes你不应该强调这一点。 – Crispy 2013-04-25 20:43:15