Split string into strings by length?

后端 未结 15 2149
半阙折子戏
半阙折子戏 2020-11-27 06:31

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 s

15条回答
  •  无人及你
    2020-11-27 06:57

    >>> 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']
    

提交回复
热议问题