Home > Article > Backend Development > What does join mean in python?
There are two functions .join() and os.path.join() in Python. Their specific functions are as follows:
. 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
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!