EN
Python - convert list to string
0 points
In this article, we would like to show you how to convert list to a string in Python.
Quick solution:
xxxxxxxxxx
1
my_list = ["a", "b", "c"]
2
text = "".join(my_list)
3
4
print(text) # abc
In this example, we convert list to a string using join()
method with a specified separator. This time as a separator we use a single space (" "
).
xxxxxxxxxx
1
my_list = ["dirask", "is", "awesome"]
2
text = " ".join(my_list)
3
4
print(text) # dirask is awesome
Output:
xxxxxxxxxx
1
dirask is awesome
Note:
We use a single space (
" "
) as a separator injoin()
method. To use a different separator, simply type new character in double-quotes before the metod.xxxxxxxxxx
1"_".join(my_list)
Output:
xxxxxxxxxx
1dirask_is_awesome