Federer
Federer

Reputation: 34745

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

Upvotes: 25

Views: 16244

Answers (4)

Rasmus Kaj
Rasmus Kaj

Reputation: 4360

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.

Upvotes: 9

mculp
mculp

Reputation: 2687

Unicode.

Upvotes: 11

SilentGhost
SilentGhost

Reputation: 319601

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

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

Upvotes: 47

toasteroven
toasteroven

Reputation: 2790

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

Upvotes: 4

Related Questions