List Append in Python

Level 243 keystrokes

This adds 3 to the end of the list and prints [1, 2, 3]. The append() method adds an element to the list.

Python code

# Create a list with two initial elements
1items = [1, 2]
# append() adds a new element to the end of the list
# The list is modified in place (no new list is created)
2items.append(3)
# Print the updated list showing all three elements
3print(items)

Output

[1, 2, 3]
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • (× 2
  • )× 2
  • ,× 1
  • .× 1
  • [× 1
  • ]× 1
  • =× 1

More Python examples at level 2

← Python typing practice