For example, I have a variable with a string

a = "Hello World" 

and I need what would output

 he ll o wo rl d 

    4 answers 4

     for i in range(0, len(a), 2): print(a[i:i+2]) 

    or so

     from itertools import zip_longest print('\n'.join(''.join(i) for i in zip_longest(*([iter(a)] * 2), fillvalue=''))) 

      Another option is to use the textwrap module textwrap

       import textwrap a = "Hello World" print('\n'.join(textwrap.wrap(a, 2))) 

        As a perverted alternative:

         from io import StringIO a = StringIO("Hello World") while True: s = a.read(2) if not s: break print(s) 
           string = 'hello world' for num in range(0, len(string), 2): print(string[num : num + 2])