Python: getting started

Lesson 02 · 11 min

Lists, dicts, loops

A list is a sequence. A dict is key → value. for goes over the elements, not by index, unless you need the index.

items = ["tea", "coffee"] is a list; indexes start at zero; append adds to the end. user = {"id": 1, "name": "Ada"} is a dict. The key in quotes, a colon, the value. Access: user["name"]. No such key — KeyError. .get("name") returns None if the key is missing.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.