Home > Backend Development > Python Tutorial > How to convert list to string in python

How to convert list to string in python

青灯夜游
Release: 2023-01-05 16:14:13
Original
106287 people have browsed it

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)".

How to convert list to string in python

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]
Copy after login

''.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)
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template