python / beginner
Snippet
Adding Items to a List
The .append() method is the standard way to add a single new element to the very end of an existing list.
snippet.py
1
2
3
tasks = ["Clean", "Cook"]tasks.append("Read")print(tasks)
Breakdown
1
tasks = ["Clean", "Cook"]
Initializes a list with two string elements.
2
tasks.append("Read")
Adds the string 'Read' as the third item in the list.