`join()` Method

The  str.join(iterable) method concatenates all string elements from an iterable (list, tuple, dict keys, etc.) into a single string, inserting the calling string as the separator between each element.

Element Type Warning!

Elements in the iterable must be strings

Generic Syntax:

concatenated_str_elements = 'sep'.join(iterable)

Example 1: Lists

words = ['hello', 'world']
print(', '.join(words))
hello, world

Example 2: Dictionary

names = {'names': ['John', 'Jane']}
print(', '.join(names.get('names', [])))
John, Jane

How does the .get('key', []) work?

Dictionary contents: {'names': ['John', 'Jane']}
                    ↑ key     ↑ value (a LIST)
What if the key is missing?

 Return an empty list[] , so  .join()  always works. The  []  never replaces an existing value—it only kicks in when the key is missing.

Powered by Forestry.md