Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

Is it possible to split a python string every nth character?

For example, suppose I have a string containing the following:


How can I get it to look like this:


1 Answer

0 votes
by (106k points)

There are many ways by which you can split string’s every nth character some of the import methods are as follows:-

The first method you can use to solve this problem is by using the len() function.

abc= '1234567890'

n = 2

[abc[i:i+n] for i in range(0, len(abc), n)]


The second way of solving this problem is by using the regular expression module and its findall() function below is the code that shows how we can use the regular expressions to split string by nth char:-

import re



Related questions

0 votes
1 answer
asked Jul 31, 2019 in Python by Rajesh Malhotra (19.9k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.4k questions

32.5k answers


108k users

Browse Categories