Split String in Python

Published: 11 April 2020
on channel: linuxhint
11,804
85

In this video, we have explained string splitting in python. When a string of multiple words is divided into the specific number of words based on a particular separator then it is called string splitting. Most of the programming languages use the split() method to divide a string into multiple words. The return type of this method is an array for many standard programming languages. the split() method is used in Python also to divide a string into words and it returns a list of words based on the separator. .
We have explained the string splitting in python by examples.
Following is the code that is used in this video for demonstration
Example-1: Split string based on space
text ="Welcome to the linuxhint"
print("The string is spliting on the basis on white space")
print(text.split())
Example-2: Split string based on comma
country="USA,UK,France, Russia, Parkistan, India"
listCountry=country.split(',')
for i in range (0,len(listCountry)):
print(listCountry[i])
Example-3: Split string based on the specific word
proglang="Bash and c++ and php and python"
langlist=proglang.split("and")
for i in range (0,len(langlist)):
print(lanlist[i])
Example-4: Split string based on the limit (maxsplit)
person="John:student:MIT:7thsmeseter:john@gmail.com"
val1=person.split(":",2)
for i in range (0,len(val1)):
print(val1[i])


On this page of the site you can watch the video online Split String in Python with a duration of hours minute second in good quality, which was uploaded by the user linuxhint 11 April 2020, share the link with friends and acquaintances, this video has already been watched 11,804 times on youtube and it was liked by 85 viewers. Enjoy your viewing!