String to list conversion in python by R4R Team

String and list both are the different data type of different domain and structure of both data type is different. So when we want to convert string to list, we must aware of string as well as list in python.

Example of conversion-

String1='Mytext'
And we want to make a list which is look like
List= ['M', 'y', 't', 'e', 'x', 't']
In this example we take item of string one by one according to index and append in the list so we get require list.

Program-

s="Mytext"
l=list(s)
print(l)
print(len(s))
print(len(l))
if len(s)==len(l):
print("length of both is same")
else:
print("Length of both is not same")



output

['M', 'y', 't', 'e', 'x', 't']
6
6
length of both is same

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!