Using the join() Function to Concatenate Strings
The join()
function is used to concatenate multiple strings into one.
It connects elements of an iterable object like strings, lists, tuples, etc., using a specific delimiter.
Using the join function
'delimiter'.join(iterable_object)
Examples of Using join()
The join()
function takes an iterable that includes strings as a parameter (input required to execute the function).
This function inserts the specified delimiter between each element of the string, joining them into a single string.
join function example
words = ['Enjoyable', 'Python', 'Programming'] sentence = ' '.join(words) print("sentence:", sentence) # "Enjoyable Python Programming"
The join()
function is useful for concatenating multiple strings into one or converting a list or tuple into a string.
Converting a list to a string
words = ['apple', 'banana', 'cherry', 'date', 'fig'] word_joined = ', '.join(words) print("word_joined:", word_joined)
Mission
0 / 1
Concatenate Strings
Join the strings in the given list with ' - ' as a separator and print the result. The expected output is Hello - World - Python
.
words = ['Hello', 'World', 'Python']
result = ' - '.join(
)
print(result)
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help
Code Editor
Run
Generate
Execution Result