You are here: Home / Topics / String to list conversion in python

String to list conversion in python

Filed under: Python on 2022-08-26 13:25:41

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


About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.