join() Method is also a very important string method , It is split() The inverse of method , Used to list ( Or tuples ) Multiple strings contained in are concatenated into one string .
Want to learn more split() Method reader , Can be read 《Python split() Method 》 section .
Use join() Method to merge strings , It will list ( Or tuples ) Multiple strings in are connected together with fixed separators . for example , character string “c.biancheng.net” It can be seen as passing through the separator “.” take [‘c’,‘biancheng’,‘net’] The result of merging a list into a string .
newstr = str.join(iterable)
The meanings of parameters in this method are as follows :
>>> list = ['c','biancheng','net']
>>> '.'.join(list)
'c.biancheng.net'
>>> dir = '','usr','bin','env'
>>> type(dir)
<class 'tuple'>
>>> '/'.join(dir)
'/usr/bin/env'