How to Convert a List of Characters to a String in Python (With and Without join)

Let’s see how to convert char to string in Python.

Asume given char list is :

Char : ['m', 'y', 'c', 'h', 'a', 'r']

And we would like to convert it to:

String : mychar 

There are a few ways to do that:

The code

The easiest way to convert a list of chars to string in Python is to start with an empty string, iterate over the character list, and append each character to build the final result.

char = ['m', 'y', 'c', 'h', 'a', 'r']


def charToString(char):
    string = ""

    for x in char:
        string += x

    return string


print(charToString(char))

char to string list

Alternative method

There is an other method. You can use join function to join char into string.

i = ['m', 'y', 'c', 'h', 'a', 'r']


def chartostring(i):
    string = ""

    return string.join(i)


print(chartostring(i))

As you may notice .join() function is making chars a one string.

See also  How to Convert NumPy Array to Python List (Using .tolist() and list() Methods)
char to string list
char to string list

You can also use the join method to convert a character list to a single Python string in one step, which is usually clearer and more idiomatic for this task. You may think this looks uglier but in fact tostring() is faster than .join() in this case.

Keeping performance in mind this method is recommended. Hope now you know how to convert char to string with Python.

See also  Using Python Tracebacks to Understand Error Flows