16.join usage (splicing list which must be str type)

= S1 'Alex'
S2 = '+'. the Join (S1)
Print (S2, type (S2)) # L + E + A + X <class 'STR'>
L1 = [ 'red', 'Xiaogang' 'Bob']

Premise: the list of elements must all type str

s3 = ':'. join ( l1) returns a list of a character string as follows:
Print (S3) red #: Xiaogang: Bob
print ( '' join (l1) .) # Xiaogang Alice Bob
Note: The preceding the 'what is filled inside, by returning the string which is connected, which is empty, it will be a list of strings into a void-
a = [' ',' 12 ',' 3 ',' '] must be a string list #
a1 =' '. join (a ) >>> 123 # 123 in front of a space Important
a1 =' + '. join ( a) >>> + 12 + 3 + # first + sign in front of spaces, the first space list spliced together, a + 3 also behind the splice '

Guess you like

Origin www.cnblogs.com/pythonblogs/p/11032153.html
Recommended