10.26. list
Type Conversion Function¶
Python has a built-in type conversion function called
list
that tries to turn whatever you give it
into a list. For example, try the following:
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
The string “Crunchy Frog” is turned into a list by taking each character in the string and placing it in a list. In general, any sequence can be turned into a list using this function. The result will be a list containing the elements in the original sequence. It is not legal to use the list
conversion function on any argument that is not a sequence.
It is also important to point out that the list
conversion function will place each element of the original sequence in the new list. When working with strings, this is very different than the result of the split
method. Whereas split
will break a string into a list of “words”, list
will always break it into a list of characters.