What does 'u' mean in a list?

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

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 common this is, if you'd like to see how I came across it, I'll happily edit the post.

回答1:

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

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


回答2:

Unicode.



回答3:

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.



回答4:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!