Split String in Python

Veröffentlicht am: 11 April 2020
auf dem Kanal: 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])


Auf dieser Seite können Sie das Online-Video Split String in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer linuxhint 11 April 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 11,804 Mal angesehen und es wurde von 85 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!