简体   繁体   English

列表中的“你”是什么意思?

[英]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 ie 只是打印一个列表,每个元素似乎都有一个u在它前面,即

[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. 由于我不知道这有多常见,如果您想看看我是如何遇到它的,我会很乐意编辑这篇文章。

it's an indication of unicode string. 它表示unicode字符串。 similar to r'' for raw string. 类似于原始字符串的r''

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

The u just means that the following string is a unicode string (as opposed to a plain ascii string). u只是意味着以下字符串是一个unicode字符串(而不是普通的ascii字符串)。 It has nothing to do with the list that happens to contain the (unicode) strings. 它与恰好包含(unicode)字符串的列表无关。

我相信u'前缀创建一个unicode字符串而不是常规的ascii

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM