capypad
0 day streak
python / beginner
Snippet

Combining Strings with join()

The join() method is a highly efficient way to concatenate a list of strings into a single string, using a specific separator (like a space or a comma) between each word.

snippet.py
python
1
2
3
words = ["Python", "is", "fun"]
sentence = " ".join(words)
print(sentence)
Breakdown
1
words = [...]
A list containing individual strings.
2
sentence = " ".join(words)
Takes the space string " " and inserts it between every element in the 'words' list.
3
print(sentence)
Outputs the fully combined sentence: 'Python is fun'.