liveBook · Manning

Built-in function

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

list.append() is a Python list method that adds one object as a single new element at the end of the list.

list.append() adds exactly one object to the end of an existing list. It changes the list in place and is useful when a program builds a sequence incrementally. section 3.3.1 section 3.3.2

Append and verify

>>> items = [] >>> items.append('sammiches') >>> assert len(items) == 1 >>> items ['sammiches'] The call produces no displayed value, so inspect the list or assert its expected length. section 3.3.1

Choose append() when the intended result is one new element:

  • items.append(['chips', 'ice cream']) adds the entire list as one nested element, producing ['sammiches', ['chips', 'ice cream']]. section 3.3.2
  • items.extend(['chips', 'ice cream']) adds both strings separately; passing two arguments to append() raises TypeError. section 3.3.2
  • Use += as an alternative spelling when adding one chosen value to a list during a loop. section 12.3.3
  • For verse lines, append() incorrectly stores a reversed iterator or list as one element; extend() is needed to add each line separately. section 13.3.1
>>> items.append('sammiches')

Run the minimal REPL operation, then inspect the list with b6 or verify it with b5. section 3.3.1

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains one-argument behavior, nested-list results, assertions, and the distinction from extend(), but does not cover implementation internals.
Examples
Demonstrates picnic items, a ransom-text accumulator, and Christmas-verse lines.
What it assumes
Assumes basic Python lists, indexing, length checks, loops, and assertions while teaching list mutation through small REPL experiments.
What you can do after
Apply list.append() to collect single values, verify mutations with assertions, and diagnose accidental nesting against extend().
How it connects
Connects list.append() with Python lists, list.extend(), list.insert(), list slicing, reversed(), and string joining.

Also explained in

Compare how 2 books explain built-in function →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.