Unicode vs UTF-8 confusion in Python / Django?

前端 未结 5 1921
渐次进展
渐次进展 2020-12-14 00:53

I stumbled over this passage in the Django tutorial:

Django models have a default str() method that calls unicode()

5条回答
  •  醉梦人生
    2020-12-14 01:16

    so what is a "Unicode string" in Python?

    Python 'knows' that your string is Unicode. Hence if you do regex on it, it will know which is character and which is not etc, which is really helpful. If you did a strlen it will also give the correct result. As an example if you did string count on Hello, you will get 5 (even if it's Unicode). But if you did a string count of a foreign word and that string was not a Unicode string than you will have much larger result. Pythong uses the information form the Unicode Character Database to identify each character in the Unicode String. Hope that helps.

提交回复
热议问题