python – 按字符串长度分割字符串?

有没有办法取长度为4 * x个字符的字符串,并将其切成4个字符串,每个x个字符长,不知道字符串的长度?

例如:

>>>x = "qwertyui"
>>>split(x, one, two, three, four)
>>>two
'er'
>>> x = "qwertyui"
>>> chunks, chunk_size = len(x), len(x)/4
>>> [ x[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
['qw', 'er', 'ty', 'ui']
翻译自:https://stackoverflow.com/questions/13673060/split-string-into-strings-by-length

转载注明原文:python – 按字符串长度分割字符串?