0%

Lists · practice

Create a List

You create a by placing comma-separated values inside square brackets. Each becomes one item.

Try it

Python prints the brackets, commas, and quotes so you can see the list structure. The call to type() reports list.

Values first, name second

The right side of an creates the list. The name on the left lets you use that list again:

Try it

Spaces after commas are not required by Python, but they make the list easier to read. A list can also span several lines:

Try it

The trailing comma after the last item is allowed. It makes later editing convenient, but you do not need it for a short one-line list.

Count the items, not the punctuation

This list contains three items:

Try it

You already used len() with . With a list, it returns the number of items rather than the number of characters.

What does this code print?

drinks = ["tea", "coffee"]
print(len(drinks))

Your turn

In the editor, replace the empty list with the three destinations named in the instructions. Printing the whole list lets you check both its values and their order. Three items, one list, and much less name juggling.

Task

Create a named destinations containing exactly these three in this order:

  1. "Lisbon"

  2. "Seoul"

  3. "Nairobi"

Then print the complete list.