Split String in Python

Publicado em: 11 Abril 2020
no canal de: 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])


Nesta página do site você pode assistir ao vídeo on-line Split String in Python duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário linuxhint 11 Abril 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 11,804 vezes e gostou 85 espectadores. Boa visualização!