Remove the First Element from a List in Python

  • Post category:List

Removing the first element from a list is a common operation in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to remove the first element from a list efficiently.

Example 1:

fruits = ['apple', 'banana', 'orange', 'kiwi']
fruits.pop(0)
print(fruits)

Output: [‘banana’, ‘orange’, ‘kiwi’]

Example 2:

numbers = [1, 2, 3, 4, 5]
numbers = numbers[1:]
print(numbers)

Output: [2, 3, 4, 5]