Contents
Convert List of Characters to String
Given a list of characters chars
, we need to join these characters into a string.
To convert a given list of characters into a string in Python, we can use String.join() method. The join() method takes an iterable as argument, and joins the items in the iterable with the calling string as separator string.
Since we need to just join the chars to form a string, we take an empty string as separator string.
Syntax
The syntax of the expression to join the items in list of characters chars
using String.join() method is
''.join(chars)
Run The above expression returns a string formed by joining the items of the given list chars
.
Example
In the following program, we take a list of characters in chars
and join them into a string.
Python Program
myList = ['a', 'p', 'p', 'l', 'e']
output = ''.join(myList)
print(output)
Run Output
apple
Summary
In this tutorial of Python Examples, we learned how to join the items in given list of characters into a string using String.join() method, with the help of well detailed examples.
Related Tutorials
- How to Get List of all Files in Directory and Sub-directories?
- Python Program to Find Largest Number in a List
- How to Append List to Another List in Python? – list.extend(list)
- Python List of Functions
- Python List – Add Item
- Python – How to Create an Empty List?
- Python Program to Find Smallest Number in List
- How to Insert Item at Specific Index in Python List?
- Shuffle Python List
- How to Reverse Python List?