How to convert list to string in python

(*-*)浩
Release: 2019-07-09 10:05:51
Original
42514 people have browsed it

Use str in the python list to convert all values ​​into strings, and use the join method to splice the list into a string.

How to convert list to string in python

The Python join() method is used to connect elements in the sequence with specified characters to generate a new string. (Recommended learning: Python video tutorial)

Grammar

join() method syntax:

str.join(sequence)
Copy after login

Parameters

sequence -- The sequence of elements to be connected.

Return value

Returns a new string generated by concatenating elements in the sequence by the specified characters.

Examples

>>> ls1 = ['a', 1, 'b', 2]
>>> ls2 = [str(i) for i in ls1]
>>> ls2
['a', '1', 'b', '2']
>>> ls3 = ''.join(ls2)
>>> ls3
'a1b2'
Copy after login

For more Python related technical articles, please visit the Python Tutorial column to learn!

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