码迷,mamicode.com
首页 > 编程语言 > 详细

python 字符串前缀

时间:2017-04-05 21:17:54      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:logs   str   需要   sage   raw   对象   输出   python   pytho   

普通字符串

一般字符串都是已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 字符串前缀

标签:logs   str   需要   sage   raw   对象   输出   python   pytho   

原文地址:http://www.cnblogs.com/WeyneChen/p/6670647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!