List Clear in Python

Level 247 keystrokes

This removes all elements from a list using the clear() method, leaving an empty list.

Python code

# Create a list with five numbers
1nums = [1, 2, 3, 4, 5]
# clear() removes all elements from the list
# The list becomes empty but still exists
2nums.clear()
# Print the now-empty list
3print(nums)

Output

[]
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.

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

More Python examples at level 2

← Python typing practice