How can a Python list be converted into a string?

Convert a list to a string using the join function.

my_list = ['a', 'b', 'c']
my_string = ''.join(my_list)
print(my_string)  # 输出: abc

To add a separator between each element, specify the separator in the join function.

my_list = ['a', 'b', 'c']
my_string = '-'.join(my_list)
print(my_string)  # 输出: a-b-c
bannerAds