python split string size code example

Example 1: split string by length python

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

Example 2: how split string in python by size

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

Example 3: python split string size

some_string="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
x = 3 
res = [some_string[y - x:y] for y in range(x, len(some_string) + x, x)]
print(res)

Tags:

Misc Example