Python学习笔记

Python字符串前加字母u或者r区别

2016-08-28  本文已影响804人  Viking_Den

Python中,u表示unicode string,表示使用unicode进行编码,没有u表示byte string,类型是str,在没有声明编码方式时,默认ASCI编码。如果要指定编码方式,可在文件顶部加入类似如下代码:

# -*- coding: utf-8 -*-  

utf-8是一种支持中文的编码格式。

字母前加r表示raw string,也叫原始字符串常量。一般用在一下两个方面:

search = re.compile(r'\s*')
path = r'e:\text'
上一篇 下一篇

猜你喜欢

热点阅读