Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I want to know, how we can convert string data into a list format data?

For example: A string is like text = "a,b,c". After the conversion, text == ['a', 'b', 'c'] and hopefully text[0] == 'a', text[1] == 'b'?

1 Answer

0 votes
by (108k points)

Kindly refer to the below code for converting the string into list format:

text = 'a,b,c'

text = text.split(',')

text

[ 'a', 'b', 'c' ]

Or, you can also take the help of an in-built function in Python named eval():

text = 'a,b,c'

text = eval('[' + text + ']')

For more information, you can refer to the following video:

 

Related questions

0 votes
1 answer
asked Sep 27, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...