Free Online Flashcard Deck

6 Python Collections Free Online FlashCards

Study 6 Python Collections with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a Python list?

Back

A list is an ordered, mutable collection written with square brackets, such as `[1, 2, 3]`.

02
Front

How do `append()` and `extend()` differ?

Back

`append()` adds one item to the end of a list, while `extend()` adds each item from an iterable.

03
Front

What is a list comprehension?

Back

A list comprehension creates a new list from an iterable, optionally filtering items, in a compact expression such as `[n * n for n in range(1, 6)]`.

04
Front

What is a Python tuple?

Back

A tuple is an ordered, immutable collection. Its items cannot be replaced or deleted after creation.

05
Front

How do you write a one-item tuple?

Back

The comma creates a tuple, so a one-item tuple must be written `(42,)`; `(42)` is just the integer expression `42`.

06
Front

What does zero-based indexing mean?

Back

Python uses zero-based indexing: the first item has index `0`. A negative index counts backward from the end.

07
Front

What is Python slice syntax?

Back

A slice uses `sequence[start:stop:step]`; `start` is included, `stop` is excluded, and omitted parts use the sequence boundaries as appropriate.

08
Front

What does a list slice copy?

Back

For lists, `numbers[:]` creates a shallow copy: it copies the outer list but keeps references to the same nested objects.

09
Front

What does `second = first` do for a list?

Back

Assignment creates another reference to the same object; it does not automatically copy a collection. Mutating through either reference affects that shared object.

10
Front

When should you use `enumerate()`?

Back

Use `enumerate()` when a loop needs both each element and its index, as in `for index, color in enumerate(colors):`.

11
Front

What is a Python dictionary?

Back

A dictionary maps unique, hashable keys to values. It is mutable and written with `key: value` pairs inside braces.

12
Front

Why use `dict.get()`?

Back

`get()` returns a key's value or a default when the key is absent, avoiding the `KeyError` that direct bracket lookup can raise.