def cut_text(text, lenth): # lenth 表示切割的子字符串的長度
????import re
????textArr = re.findall('.{'+str(lenth)+'}', text)
????textArr.append(text[(len(textArr)*lenth):])
????if textArr[-1] =='': textArr.pop()
????return textArr
示例:
結(jié)果:
['ABCA', 'ABCA', 'ABCA', 'ABCA', 'ABCA']