How python splits words in a line
This article mainly introduces how python splits words in one line, which is very detailed and has certain reference value. Friends who are interested must finish it!
Split words in a line
You don't need a special algorithm to split a word into a line. To do this, we can use the keyword split (). Here, I wrote two ways to segment words.
Method 1-use iteration
My_string = "This is a string in Python" start= 0 end= 0 my_list = [] for x in my_string: end=end+1 if (end'): my_list.append (my_ string [start: end+1]) start=end+1 my_list.append (my_ string [start: end+1]) print (my_list)
Output quantity
['This','is','a', 'string','in', 'Python']
Method II- uses the segmentation function
My_string = "This is a string in Python" my_list = my_string.split ('') print (my_list)
Output quantity
['This','is','a', 'string','in', 'Python'] these are all the contents of the article "how to split words in a line by python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!