join
Examples¶
The general syntax for this method is:
'connecter'.join(list_name)
join
combines all of the elements in list_name
into a single string.
Note that each element in list_name
MUST be a string data type.
The 'connector'
determines the string that “glues” the list elements
together. 'connector'
may be the empty string (''
), any single
character, multiple characters, or special characters (like '\t'
or
'\n'
).
Example
1 2 3 4 5 6 7 8 9 10 11 12 | digit_strings = ['1', '2', '3', '4']
words = ['Hello', 'World', '!']
new_string = ''
new_string = '+'.join(digit_strings)
print(new_string)
new_string = ''.join(words)
print(new_string)
new_string = '\n'.join(words)
print(new_string)
|
Output
1+2+3+4
HelloWorld!
Hello
World
!