Turning a Python String Into a List



This is not really related to any Code Academy exercises (or might be).

If I have a string such as a = 'hello my name is max', how would I turn it into a list that looks like lst = ['hello my name is max']

Thank you!


well you could do something like:

a = 'hello my name is max'
lst = [a]
print lst

you can simply store the variable into the list, this will store the string in the list. Or if you want you can also first declare the list:

lst = []

and then use the build in append() function to append to the list:


i would choice the first approach


I just want to ask a question that's not completely related, but is append similar to the push method in JS?


apart from the fact that under the hood they are implanted different (since it are different languages), yes, they both add (or rather append) items to a list/array.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.