Remember
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.
Follow the example, change its sample, and compare what happens.
Explain the result and test your understanding.
Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.
Follow the code and watch its state change. Guided simulation.
text = ', '
result = text.join(["tea", "milk", "water"])
print(result)Top-level scope
', 'Object 2 · str'tea, milk, water'join() puts the separator between strings from an iterable. Every item must be a string.
(no output)
What do you expect this program to print?
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'Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.
Choose a sample and follow its execution. Guided simulation.
text = ', '
result = text.join(["tea", "milk", "water"])
print(result)Top-level scope
', 'Object 2 · str'tea, milk, water'The example has finished. Compare the final output with the values and references above.
tea, milk, water
What do you expect this program to print?
text = ', '
result = text.join(["tea", "milk", "water"])
print(result)join() MethodThe 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.
separator_string.join(iterable_of_strings)
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.words = ['Python', 'is', 'awesome']
sentence = ' '.join(words)
print(sentence)
Python is awesome
date_parts = ['2025', '05', '14']
date_string = '-'.join(date_parts)
print(date_string)
2025-05-14
items = ('apple', 'banana', 'cherry')
result = ', '.join(items)
print(result)
apple, banana, cherry
+.TypeError.print(','.join(['Python', 3]))
TypeError: sequence item 1: expected str instance, int found
join() is often used in questions involving string formatting or list manipulation. It’s faster and more efficient than using loops for string concatenation.
join() combines elements of an iterable into one string.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
Connect what you noticed in the example with the idea below.
join() puts the separator between strings from an iterable. Every item must be a string.
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.