Python字符串前缀

python学习网 2019-10-30 19:11:01

1,r/R表示raw string(原始字符串)

#!/usr/bin/python
str1 = 'hello \n world'
str2 = r'hello \n world'
print(str1)
print(str2)

2,u/U表示unicode string(unicode编码字符串)

#!/usr/bin/python
str1 = '\u4f60\u597d\u4e16\u754c'
str2 = u'\u4f60\u597d\u4e16\u754c'
print(str1)
print(str2)

3,b/B表示byte string(转换成bytes类型)

#!/usr/bin/python
str1 = 'hello world'
str2 = b'hello world'
print(type(str1))
print(type(str2))

 

阅读(2366) 评论(0)