What's the u prefix in a Python string?

前端 未结 6 1028
南笙
南笙 2020-11-21 22:45

Like in:

u\'Hello\'

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

If so, since when is it available?

6条回答
  •  北海茫月
    2020-11-21 23:38

    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.

提交回复
热议问题