Home > Backend Development > Python Tutorial > Why string.join(list) instead of list.join(string)

Why string.join(list) instead of list.join(string)

anonymity
Release: 2019-05-25 14:38:53
Original
3536 people have browsed it

Convert string to list

Why string.join(list) instead of list.join(string)

##Convert string to list

Call

list()Function

tmpstr = 'abc'

tmplist = list(tmpstr)

list to string

Call

joinfunction

tmplist = ['a','b','c']

tmpstr = ''.join (tmplist)

Syntax 'sep'.join(seq)

Parameter description

sep: separator, can be empty

seq: to link Sequence of elements, strings, tuples, dictionaries

Using sep as the separator, merge all elements of seq into a new string

Return value: Return a separator with sep The string generated after concatenating each element

The above is the detailed content of Why string.join(list) instead of list.join(string). 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