What's the u prefix in a Python string?

前端 未结 6 1035
南笙
南笙 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:29

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

    Yes.

    If so, since when is it available?

    Python 2.x.

    In Python 3.x the strings use Unicode by default and there's no need for the u prefix. Note: in Python 3.0-3.2, the u is a syntax error. In Python 3.3+ it's legal again to make it easier to write 2/3 compatible apps.

提交回复
热议问题