How to convert a list to a string in Python

Posted on: March 21st, 2023
By: Tadeo Martinez

Use the Join function

letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

''.join(letters)

# Output
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

Note that you can add any character to separate the list by. In my example, I don’t have any character or space so the list outputs altogether.

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *