split() function in python by R4R Team

Split() in python is a in-build function and its work to convert the string to the list.

input in split() - string
output in split() - list

example -

s="My-String"
and we want to split that string like l=['My','String']

program -

s="My-text"
l=s.split("-")
print(l)

s="My.string"
l=s.split(".")
print(l)

s="first-second-third-fourth-fifth-sixth"
l=s.split("-")
print(l)

s="one,two,three"
l=s.split(",")
print(l)


output -

['My', 'text']
['My', 'string']
['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
['one', 'two', 'three']


In this program, we seprate first and third string at the basis of '-' and last string is split at the basis of ','

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!