capypad
0 day streak
python / beginner
Snippet

Joining List Elements into a String

The join() method takes all items in an iterable (like a list) and joins them into one string. A string must be specified as the separator, which will be placed between the items.

snippet.py
python
1
2
3
words = ['Python', 'is', 'awesome']
result = ' '.join(words)
print(result)
Breakdown
1
words = ['Python', 'is', 'awesome']
Define a list of individual words.
2
result = ' '.join(words)
Combine the words into a single string, using a space character as the glue between them.
3
print(result)
Output the final concatenated string to the console.