Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
Can anyone tell me how to convert a string to list in Python?

1 Answer

0 votes
by (108k points)

For converting a string into a list, you have to split the words in the text sentence. You can use split() to do this. After that, you have to add each word as an element to the list:

def Convert(string): 

    list1 = list(string.split(" ")) 

    return list1

# Driver code     

str1 = "Welcome to Intellipaat"

print(Convert(str1)) 

The output:

['Welcome', 'to', 'Intellipaat']

If you are looking for an online course to learn Python, I recommend this Python Training program by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
asked Aug 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...