开发者

What does 'u' mean in a list?

This is the first time I've came across this. Just printed a list and each element seems to have a u in front of it i.e.

[u'hello', u'hi', u'hey']

What does it mean and why would a list have this in front of each element?

As I don't know how commo开发者_Python百科n this is, if you'd like to see how I came across it, I'll happily edit the post.


it's an indication of unicode string. similar to r'' for raw string.

>>> type(u'abc')
<type 'unicode'>
>>> r'ab\c'
'ab\\c'


Unicode.


The u just means that the following string is a unicode string (as opposed to a plain ascii string). It has nothing to do with the list that happens to contain the (unicode) strings.


I believe the u' prefix creates a unicode string instead of regular ascii

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜