What's the u prefix in a Python string?

OscarRyz picture OscarRyz · Mar 17, 2010 · Viewed 220.4k times · Source

Like in:

u'Hello'

My guess is that it indicates "Unicode", is it correct?

If so, since when is it available?

Answer

Stefan Kendall picture Stefan Kendall · Mar 17, 2010

You're right, see 3.1.3. Unicode Strings.

It's been the syntax since Python 2.0.

Python 3 made them redundant, as the default string type is Unicode. Versions 3.0 through 3.2 removed them, but they were re-added in 3.3+ for compatibility with Python 2 to aide the 2 to 3 transition.