Home > Backend Development > Python Tutorial > What does join mean in python?

What does join mean in python?

(*-*)浩
Release: 2019-07-03 10:56:04
Original
9759 people have browsed it

There are two functions .join() and os.path.join() in Python. Their specific functions are as follows:

What does join mean in python?

. join(): Connection String array. Concatenate elements in strings, tuples, and lists with specified characters (delimiters) to generate a new string

os.path.join(): Return after combining multiple paths (Recommended learning: Python Video Tutorial)

>>#对序列进行操作(分别使用'  ' 、' - '与':'作为分隔符)
>> a=['1','2','3','4','5']
>> '  '.join(a)
1 2 3 4 5
>>';'.jion(a)
1-2-3-4-5
>>'.'.join(a)
1.2.3.4.5
>>#对字符串进行操作(分别使用'  ' 、' - '与':'作为分隔符)
>>b='hello world'
>> '  '.join(b)
h e l l o   w o r l d
>>'-' .join(b)
h-e-l-l-o- -w-o-r-l-d
>>':'.jion(b)
h:e:l:l:o: :w:o:r:l:d
>>#对元组进行操作(分别使用'  ' 、' - '与':'作为分隔符)
>>c=('1','2','3','4','5')
>>'  '.join(c)
1 2 3 4 5
>>'-'.join(c)
1-2-3-4-5
>>':'.join(c)
1:2:3:4:5
>>#对字典进行无序操作(分别使用'  ' 、' - '与':'作为分隔符)
>>d={'name1':'a','name2':'b','name3':'c','name4':'d'}
>>'  '.join(d)
name1 name2 name3 name4
>>'-'.join(d)
name1-name2-name3-name4
>>':'.join(d)
name1:name2:name3:name4
>>#对目录进行操作
>> import os
>>os.path.join('/hello/','good/date','datbody')
hello/good/date/datbody
Copy after login

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

The above is the detailed content of What does join mean 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