liveBook · Manning

Join

As explained in Python How-To

The Python str.join method returns one string by concatenating the elements of an iterable with the calling string inserted between adjacent elements.

Need to turn several strings into one readable value? Call join on the delimiter, not on the list: separator.join(iterable). Python inserts the calling string between adjacent elements, and the iterable can be a list, tuple, set, dictionary, map object, or another iterable. section 2.3.2

Format a style setting

style_settings = ["font-size=large", "font=Arial", "color=black", "align=center"] merged_style = ", ".join(style_settings) print(merged_style) # output: font-size=large, font=Arial, color=black, align=center section 2.3.2

Choose the joining technique according to the shape of the task:

  • Use join when individual strings are already stored in an iterable, especially when there are many of them. section 2.3.4
  • Use concatenation for a small number of strings; consider f-strings first when bringing related strings together. section 2.3.4
  • Remember the direction of the call: the separator joins each item in the iterable, rather than the iterable providing the method. section 2.3.2

How Python How-To covers it

How deep it goes
Explains the call direction, accepted iterable types, and selection against concatenation and f-strings, without descending into implementation internals.
Examples
Demonstrates comma-separated style settings and contrasts joining with task-list formatting.
What you can do after
Apply it via Python's str.join method to create readable delimited strings from iterable elements.
How it connects
Connects string joining with delimiters, iterables, string concatenation, f-strings, and split.

Also explained in

Compare how 6 books explain join →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python How-To. The section links point to the parts of the book it draws on.