Python Mini Tutorial — Converting A String To A List Of Characters

Christopher Franklin
Weekly Python
Published in
2 min readJan 13, 2021

Welcome to our Python Mini Tutorial series here on Weekly Python! We are providing you with bite-size snacks of Python tips and tricks daily.

Today's mini-tutorial is how to convert a String into a List and then back again.

We will start by defining a String to work with:

>>> s = 'Weekly Python'

To convert this string into a list, we just pass it into the built-in list function:

>>> l = list(s)
>>> print(l)
['W', 'e', 'e', 'k', 'l', 'y', ' ', 'P', 'y', 't', 'h', 'o', 'n']

You can now manipulate the individual characters and mutate them as you would any other list in Python. For instance, if we want to change the W to a lowercase character:

>>> l[0] = 'w'

Finally, we can take our modified list of characters and convert it back to a string by using the join method.

>>> s2 = ''.join(l)
>>> print(s2)
'weekly Python'

To use join, we call it on the character we want to use as the joiner, which in this case is an empty string.

And that concludes today’s mini-tutorial! Are you looking for a challenging project to work on in Python? You should check out the Weekly Python Coding Challenge, a free weekly email that will give you a new challenging project to build in Python!

--

--