Python Reference Library →

Python String join() Method – Combine Strings Easily

Let’s look at string join() method – combine strings easily

  1. Notice

    join() puts the separator between strings from an iterable. Every item must be a string.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
text = ', '
result = text.join(["tea", "milk", "water"])
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str', 'Object 2 · str'tea, milk, water'
This step

join() puts the separator between strings from an iterable. Every item must be a string.

Picture string join() method – combine strings easily

join() puts the separator between strings from an iterable. Every item must be a string.

Image brief

Alt text
A diagram for Python String join() Method – Combine Strings Easily. Instructions: text = ', ' result = text.join(["tea", "milk", "water"]) print(result). Displayed result: tea, milk, water. The final example bindings are text --> object 1 (str); result --> object 2 (str). object 1: ', '; object 2: 'tea, milk, water'
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python String join() Method – Combine Strings Easily". Teaching focus: join() puts the separator between strings from an iterable. Every item must be a string. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS text = ', ' result = text.join(["tea", "milk", "water"]) print(result) | v DISPLAYED RESULT tea, milk, water FINAL BINDINGS text --> object 1 (str) result --> object 2 (str) object 1: ', ' object 2: 'tea, milk, water' Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python String join() Method – Combine Strings Easily. Instructions: text = ', ' result = text.join(["tea", "milk", "water"]) print(result). Displayed result: tea, milk, water. The final example bindings are text --> object 1 (str); result --> object 2 (str). object 1: ', '; object 2: 'tea, milk, water'

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
text = ', '
result = text.join(["tea", "milk", "water"])
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str', 'Object 2 · str'tea, milk, water'
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
tea, milk, water

What do you expect this program to print?

What does this example display?

text = ', '
result = text.join(["tea", "milk", "water"])
print(result)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

tea, milk, water

Follow the printed values in order. The output is: tea, milk, water

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

join() puts the separator between strings from an iterable. Every item must be a string.

join() puts the separator between strings from an iterable. Every item must be a string.

More examples and reference

Python String join() Method

The join() method in Python is used to combine a list of strings into one single string, with a specified separator between each element.

It is called on a string (used as a separator) and passed an iterable (like a list or tuple) of strings.

Syntax

separator_string.join(iterable_of_strings)

Parameters:

  • separator_string – The string that will be placed between each item (e.g., space, comma, hyphen).
  • iterable_of_strings – A list, tuple, or other iterable containing strings.

Returns:

  • A new string that is the concatenation of all strings in the iterable, separated by the separator.

Example 1: Join List with Spaces

words = ['Python', 'is', 'awesome']
sentence = ' '.join(words)
print(sentence)
Python is awesome

Example 2: Join List with Hyphens

date_parts = ['2025', '05', '14']
date_string = '-'.join(date_parts)
print(date_string)
2025-05-14

Example 3: Join Tuple with Commas

items = ('apple', 'banana', 'cherry')
result = ', '.join(items)
print(result)
apple, banana, cherry

Use Case: Why Use join()?

  • Efficient way to concatenate many strings.
  • Useful in formatting output (like CSVs, dates, or sentences).
  • Cleaner and faster than using a loop with +.

Common Mistakes

  • All elements in the iterable must be strings. Mixing types (e.g., int or float) will raise a TypeError.

Incorrect Example:

print(','.join(['Python', 3]))
TypeError: sequence item 1: expected str instance, int found

Interview Tip

join() is often used in questions involving string formatting or list manipulation. It’s faster and more efficient than using loops for string concatenation.

Summary

  • join() combines elements of an iterable into one string.
  • The string it is called on becomes the separator.
  • All elements in the iterable must be strings.

Practice Problem

Join a list of numbers (converted to strings) with a colon ":" as a separator.

numbers = [1, 2, 3, 4, 5]
# Convert each number to string first
str_numbers = [str(num) for num in numbers]
result = ':'.join(str_numbers)
print(result)
1:2:3:4:5

What to remember

Connect what you noticed in the example with the idea below.

Remember

join() puts the separator between strings from an iterable. Every item must be a string.

Watch out for this idea

join() automatically converts every integer item to a string.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →