按长度将字符串拆分为字符串? [英] Split string into strings by length?
本文介绍了按长度将字符串拆分为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法取一个4*x
个字符长的字符串,把它剪成4个字符串,每个x
个字符长,不知道长度字符串?
Is there a way to take a string that is 4*x
characters long, and cut it into 4 strings, each x
characters long, without knowing the length of the string?
例如:
>>>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']
这篇关于按长度将字符串拆分为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文