编码:
python2支持的编码:
-
str支持8位文本和二进制数据
-
unicode用来表示宽字符Unicode文本
python3支持的编码: -
str表示Unicode文本
-
bytes表示二进制数据
-
bytearray,是一种可变的bytes类型
S=“Bugger all down here on earth!”
B=b"Bugger all down here on earth!"
import re
re.match("(.) down (.) on (.)!",S)
<_sre.SRE_Match object at 0x00000000045DA5D0>
re.match("(.) down (.) on (.)!",S).groups()
(‘Bugger all’, ‘here’, ‘earth’)
re.match("(.) down (.) on (.)!",B).groups()
(‘Bugger all’, ‘here’, ‘earth’)
re.match(b"(.) down (.) on (.)!",B).groups()
(‘Bugger all’, ‘here’, ‘earth’)
U=u"Bugger all down here on earth!"
对于python2文本:
re.match("(.) down (.) on (.*)!",U).groups()
(u’Bugger all’, u’here’, u’earth’)