liveBook · Manning

List.append

As explained in A Pythonic Adventure: From Python basics to a working web app

The Python list append method adds one item to the end of a mutable list.

`list.append(item)` adds one item to the end of a Python list. Start with an empty list, then append items as they arrive. The list keeps them in the order you add them. section 8.0

Collecting customer orders

Make an empty `orders` list, then add each order dictionary one at a time: `orders = []` `orders.append(order)` `orders.append(order1)` Afterward, `orders` can be saved as JSON instead of saving only one order. section 8.0

`append()` is especially handy when the final number of items is not known ahead of time. A menu can build its allowed responses by looping from `1` through the menu length, converting each number to text, and appending it to a list. section 4.0

orders.append(order)
orders.append(order1)

This short listing shows two dictionaries being added to the same empty list, one append call at a time. section 8.0

Saving confirmed orders

Keep one shared list while a program serves customers. When a customer confirms an order, use `orders.append(order)`. Later, save the whole list with `json.dump(orders, f, indent=4)`. Orders canceled or left unfinished do not need to be appended. section 9.0 section 9.0

A simple append routine is:

How A Pythonic Adventure: From Python basics to a working web app covers it

How deep it goes
Defines appending as adding an argument to a list’s end and applies it in loops and order collection.
Examples
Uses numbered menu choices, sample order dictionaries, and confirmed customer orders.
What it assumes
Assumes basic dictionaries while teaching empty-list creation and list methods through examples.
What you can do after
Apply it via Python lists to collect items incrementally and save accumulated orders as JSON.
How it connects
Connects lists with `range()`, `len()`, `for` loops, input validation, dictionaries, and JSON.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of A Pythonic Adventure: From Python basics to a working web app. The section links point to the parts of the book it draws on.