普通字符串
一般字符串都是已unicode编码,且和C类似,可以使用来转义,比如
a = "test test" print(a)
输出
test test
前面加r
在字符串前面加上一个 r 表示该字符串为raw string,不识别转义。
b = r"test test" print(b)
输出
test
test
这在使用正则表达式的时候很有用。
前面加b
生成字节序列对象bytearray。这在需要按字节序列发送数据时有用,比如网络发送
message = b"GET / HTTP/1.1 " s.sendall(message)
message的类型不再是str,而是bytes了。
<class 'bytes'>