join is the Python string method that concatenates iterable elements, placing the string on which it is called between them as a separator. An empty string joins elements without inserting anything. section 3.11 section 3.15
Use join when a transformation produces separate pieces that must become one string:
- Accumulate output in a list with append, then join it instead of repeatedly extending an immutable string with +=. section 3.7
- Choose the separator to match the output: use '' for a word, a space for readable text, or commas between names. section 3.11 section 3.17
- Remember that sorted returns a list, so join converts sorted characters or words back into a string. section 3.15
Translate characters, then join
output = [] for character in word: if character in 'aeiou': output.append('ub') output.append(character) translated = ''.join(output) The loop handles each character and stores pieces; the empty separator then combines them into one word. section 3.11
def myxml(tagname, content='', **kwargs):
attrs = ''.join([f' {key}="{value}"'
for key, value in kwargs.items()])
return f'<{tagname}{attrs}>{content}</{tagname}>'
See join assembling keyword-argument fragments into an XML-like opening tag, using a generator-style collection of attribute strings. section 7.3





