Concept
Gluing Lists into Strings (.join())
The reverse of `.split()` is `.join()`. Syntax feels backwards at first: the separator is the string, and your list goes inside the brackets:
python
parts = ["dev", "null"]
print("/".join(parts)) # "dev/null"
# 40. Gluing Lists into Strings (.join()) The reverse of `.split()` is `.join()`. Syntax feels backwards at first: the separator is the string, and your list goes inside the brackets: ```python parts = ["dev", "null"] print("/".join(parts)) # "dev/null" ``` Rule to remember: every item in the list must be text. Feeding an integer into `.join()` triggers a `TypeError`.
Checkpoint
How do you join `['x', 'y', 'z']` into `"x-y-z"`?
Practice
Glue `words = ["Python", "is", "cool"]` together with spaces in between using `" ".join()`.
01
Tap code blocks below to assemble
Available Blocks