×

python · level 2 · unit 3 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

.join() glues a list of strings into one line.

.join() is the opposite of .split(). You call it on the separator and hand it the list. ", ".join(guests) puts a comma and a space between every guest, making one line.

The separator only goes between items, never at the start or end, so there is no stray comma to tidy up. Any string can be the separator, such as " and " or " > ".

Every item must already be a string. A list of numbers gives a TypeError, so convert them first.

guests = ["Ana", "Ben", "Cy"]
print(", ".join(guests))
print(" and ".join(guests))
steps = ["Home", "Shop", "Socks"]
print(" > ".join(steps))

Read ", ".join(guests) as: glue the guests together with a comma and a space.