禁止转义

# 加u说明编码的方式
data_str = u'中文测试'
print('加u,说明是unicode编码的变量  ---- ', len(data_str))
加u,说明是unicode编码的变量  ----  4
# 禁止\的转义功能
r_str = r'\n'
o_str = '\\n'
print('加r,去掉反斜杠的转义功能  ---  ', r_str)
print('加\, 去掉反斜杠的转义功能  ---  ', o_str)
加r,去掉反斜杠的转义功能  ---   \n
加\, 去掉反斜杠的转义功能  ---   \n
# b开头,说明这个是一个二进制的数据类型
data_str = 'this is a test'
data_bytes = data_str.encode()
print('二进制的数据类型:--- ', data_bytes)
print('二进制的数据长度:--- ', len(data_bytes))
二进制的数据类型:---  b'this is a test'
二进制的数据长度:---  14
data_str = '中文测试'
data_bytes = data_str.encode()
print('二进制的数据类型:--- ', data_bytes)
print('二进制的数据长度:--- ', len(data_bytes))
二进制的数据类型:---  b'\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95'
二进制的数据长度:---  12
posted @ 2020-11-02 23:51  疯狂列表推导式  阅读(182)  评论(0编辑  收藏  举报