python字符串前缀 u的意思

以r或R开头的python中的字符串表示(非转义的)原始字符串

u'string'  表示 已经是 unicode 编码的 'string' 字符串
而 unicode('string') 是 即将要把 'string' 转化为 unicode 编码(但在执行这条语句之前,还不一定是unicode编码)
文件开始,是整体中的字符编码。一般使用 #coding:utf-8  最好还是使用utf-8

unicode 初始化 源码

1
2
3
4
5
6
7
8
9
10
11
     def  __init__( self , string = u' ', encoding=None, errors=' strict'):  # known special case of unicode.__init__
         """
         unicode(object='') -> unicode object
         unicode(string[, encoding[, errors]]) -> unicode object
         
         Create a new Unicode object from the given encoded string.
         encoding defaults to the current default string encoding.
         errors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'.
         # (copied from class doc)
         """
         pass

猜你喜欢

转载自blog.csdn.net/rocling/article/details/81007067