description
The join() method in Python is used to concatenate elements in a sequence with specified characters to generate a new string.
grammar
'sep'.join(sequence)
parameter
- sequence: The sequence of elements to be connected, which can be a tuple, list, string, dictionary
- sep: Separator (,.-etc.), can be empty
return value
Use sep as the separator to merge all the elements in the sequence into a new string, and return a new string generated by connecting the elements with the separator sep
Instance
a = ['A','B','C','D','E','F','G']
print(' '.join(a)) # A B C D E F G 以空格作为连接符
b = ('A','B','C','D','E','F','G')
print(''.join(b)) # ABCDEFG 直接相连
c = 'ABCDEFG'
print(','.join(c)) # A,B,C,D,E,F,G 以逗号作为连接符
d = {
'hello':1,'good':2,'boy':3,'girl':4}
print(' '.join(d)) # hello good boy girl 以空格作为连接符