How to Split String For Certain Number of Times in Python


In this example, we will learn how to match and split a string for a specified number of times using the split function in Python.

Source Code

import re

str1 = 'I love Python'

r = re.split('s', str1, 1)

print(r)

Output:

['I', 'love Python']
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments