What's the u prefix in a Python string?

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

    It's Unicode.

    Just put the variable between str(), and it will work fine.

    But in case you have two lists like the following:

    a = ['co32','co36']
    b = [u'co32',u'co36']
    

    If you check set(a)==set(b), it will come as False, but if you do as follows:

    b = str(b)
    set(a)==set(b)
    

    Now, the result will be True.

提交回复
热议问题