Python's str.join() concatenates elements from an iterable, inserting the calling string between adjacent elements. It returns a new string and leaves the original list unchanged. section 3.3.9 section 3.8
Join picnic items
Given items = ['soda', 'sammiches', 'chips', 'apples'], write ', '.join(items) to produce 'soda, sammiches, chips, ice cream' in the demonstrated interaction. The separator belongs before .join(), which receives the list. section 3.3.9
Use join() when a program has assembled pieces that must become one string:
- Combine randomly selected adjectives with ', '.join(random.sample(adjectives, k=3)), then insert the result into an f-string. section 9.3.6
- Combine verse lines with '\n'.join(lines), or separate complete verses with '\n\n'.join(verses). section 13.3.1 section 13.3.3
- Reconstruct processed text with ''.join(...), preserving the original characters between transformed words. section 16.3.1
- Create a password by joining sampled words on the empty string. section 20.1.6
>>> ', '.join(items) 'soda, sammiches, chips, ice cream'
Inspect the interactive join example and its comma-space output. section 3.3.9





