Convert List to String in Python

  • Post category:String

In Python, you can convert a list to string with the join() function. The join() function takes a list as input and creates a string. The best part is that the join() function can be used with any separator. Let’s code it.

Step 1: Create a list of strings

lst =  ['C', 'o', 'd', 'e', 'A', 'l', 'l', 'o', 'w']
print("lst = ", lst)
print("lst type = ", type(lst))

Step 2: Convert list to string

str = ''.join(lst)
print("str = ", str)
print("str type = ", type(str))

Output:

lst =  ['C', 'o', 'd', 'e', 'A', 'l', 'l', 'o', 'w']
lst type =  <class 'list'>
str =  CodeAllow
str type =  <class 'str'>

Free resources to learn advanced skills: AiHints and CodeAllow