Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

list.append

Adds an item to the end of a list.

Synopsis

items.append(item)

Description

append changes the list itself. Start with an empty list, [], and grow it.

Parameters

Name Meaning
item The value to add.

Return value

Nothing (None). The list itself changes.

Example

names = []
names.append("Ada")
names.append("Grace")
print(names)
print(len(names))

It prints:

['Ada', 'Grace']
2

Common mistake

names = ["Ada"]
names = names.append("Grace")
print(names)

It prints:

None

append returns None, so this throws the list away. Write names.append("Grace") on its own line.

See also

list.pop, len

list.append in the Python documentation

Last updated 2 weeks ago