Start learning free

LESSON 111 OF 673 · LISTS I

Remove Last Item From List in Python

Lesson

Another way to change the data in a list is with the .pop() method.

.pop() removes the last element of a list and also returns the value of the removed element:

threeArr = [1, 4, 6]

# Remove last element:
oneDown = threeArr.pop()

print(oneDown) # Output: 6
print(threeArr) # Output: [1, 4]

# Remove last element again:
oneDown = threeArr.pop()

print(oneDown) # Output: 4
print(threeArr) # Output: [1]

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check