re.split(pattern, string, [maxsplit=0]):
This methods helps to split string by the occurrences of given pattern.
import re result=re.split(r'a','Dynamics') print result
Above, we have split the string “Dynamics” by “a”. Method split() has another argument “maxsplit“. It has default value of zero. In this case it does the maximum splits that can be done, but if we give value to maxsplit, it will split the string.
Let’s look at the example below −
import result=re.split(r'a','Dynamics Kinematics') print result
['Dyn', 'mics Kinem', 'tics']
Consider the following code
import re result=re.split(r'i','Dynamics Kinematics',maxsplit=1) print result
['Dyn', 'mics Kinematics']
Here, you can notice that we have fixed the maxsplit to 1. And the result is, it has only two values whereas first example has three values.