Usage of Python join

Function: string.join()

There are two functions, join() and os.path.join(), in Python. The specific functions are as follows:
    join(): Concatenate string arrays. Concatenate elements in strings, tuples, and lists with specified characters (delimiters) to generate a new string
    os.path.join(): Return after combining multiple paths

1. Function description
1. join() function

Syntax: 'sep'.join(seq)

Parameter description
sep: Separator. Can be empty
seq: element sequence, string, tuple, dictionary to be concatenated The
above syntax is: with sep as the delimiter, combine all elements of seq into a new string

Return value: Returns a string generated by concatenating the elements with the separator sep

2. os.path.join() function

Syntax: os.path.join(path1[,path2[,...]])

Return value: Return after combining multiple paths

#Operate on the sequence (use ' ' and ':' as separators respectively)
  
>>> seq1 = ['hello','good','boy','doiido']
>>> print ' '.join(seq1)
hello good boy doiido
>>> print ':'.join(seq1)
hello:good:boy:doiido
# operate on strings
  
>>> seq2 = "hello good boy doiido"
>>> print ':'.join(seq2)
h:e:l:l:o: :g:o:o:d: :b:o:y: :d:o:i:i:d:o



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325566816&siteId=291194637