How to Splitting strings in Python without split()?
The easiest way to split a string in python using the Python split() function. But in this tutorial, we will find other ways (without using the split() function) to do it.
Do split strings, using a for loop, array and append:-
In the example, first need 2 variables, a “split_value” array variable for store splitter string and another one “
Inside for-loop condition statement have an if-else condition which checking the next character is space or not. If space then appends it in
sentence = 'Python Programming tutorial'
split_value = 
tmp = ''
for c in sentence:
if c == ' ':
tmp = ''
tmp += c
# for last word
Output: [‘Python’, ‘Programming’, ‘tutorial’]
Output in Python List (Array for other programming languages) format? Use a loop to get in string format or get a single word by using indexing.
Do comment if you have any doubt and suggestion on this tutorial.
Note: This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Examples of Splitting strings without function are in Python 3, so it may change its different from python 2 or upgraded versions.