python 字符串前缀
2017-04-05 21:10
155 查看
普通字符串
一般字符串都是已unicode编码,且和C类似,可以使用\来转义,比如a = "test\ntest" print(a)
输出
test test
前面加r
在字符串前面加上一个 r 表示该字符串为raw string,不识别转义。b = r"test\ntest" print(b)
输出
test\ntest
这在使用正则表达式的时候很有用。
前面加b
生成字节序列对象bytearray。这在需要按字节序列发送数据时有用,比如网络发送message = b"GET / HTTP/1.1\r\n\r\n" s.sendall(message)
message的类型不再是str,而是bytes了。
<class 'bytes'>
相关文章推荐
- python字符串前缀 u和r的区别
- python字符串前缀 u和r的区别
- python中unicode字符串前缀u
- python2.7 中字符串前缀r与u
- Python字符串前缀U和R的区别
- python字符串前缀 u和r的区别
- [转]python中文字符串处理问题
- [python]一行搞定字符串排序
- Python Cookbook 第二版 汉化版 [Recipe 1.6] 字符串的组合
- Python Cookbook 第二版 汉化版 [Recipe 1.1] 逐个处理字符串中的各个字符
- Python天天美味(8) - 字符串中的字符倒转
- Python字符串的编码和解码
- [python]一行搞定字符串排序
- 使用python将用ASCII表示的16进制unicode编码的ASCII字符串转换为unicode字符串
- Python Cookbook 第二版 汉化版 [Recipe 1.4] 对齐字符串
- Python Cookbook 第二版 汉化版 [Recipe 1.6] 字符串的组合
- 发现Python的源代码中关于字符串fastsearch算法的一个笔误!
- Python Cookbook 第二版 汉化版 [Recipe 1.8] 检测字符串是否包含特定的字符集合
- python将字符串转成16进制的ASCii码的值
- Python Cookbook 第二版 汉化版 [Recipe 1.9] 简化字符串 translate 方法的用法