Home>Article>Backend Development> How to convert list to string in python
In python, you can use the join() method to convert a list into a string; the join() method is used to connect the elements in the list with specified characters to generate a new string, the syntax format is "' Delimiter '.join(list)".
The operating environment of this tutorial: windows7 system, python3.7 version, DELL G3 computer
In python, you can use the join() method Convert list to string.
Command:''.join(list)
Among them, the quotation marks are the separators between characters, such as ",", ";", "\ t" and so on
For example:
list = [1, 2, 3, 4, 5]
''.join(list) The result is: 12345
','.join(list) The result is: 1 ,2,3,4,5
Example:
str=[] #有的题目要输出字符串,但是有时候list更好操作,于是可以最后list转string提交 for i in range(0,a): str.append('M') str1=''.join(str)
[Related recommendations:Python3 video tutorial]
The above is the detailed content of How to convert list to string in python. For more information, please follow other related articles on the PHP Chinese website!