您也可以尝试使用第三方regex模块(不是re),它支持重叠匹配。>>> import regex as re>>> s = "123456789123456789">>> matches = re.findall(r'\d{10}', s, overlapped=True)>>> for match in matches: print match...123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
我喜欢雷克斯,但这里不需要他们。简单s = "123456789123456789"n = 10li = [ s[i:i+n] for i in xrange(len(s)-n+1) ]print '\n'.join(li)结果123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789