Python Learning Series · @onlysamarrr · Day 13 / 30

Day 13: List Methods

Day 13 covers list methods. append() adds to the end, insert() adds at a position, remove() deletes by value, pop() takes out the last item, and sort() changes the list itself and returns None.

Phase: Beginner · Reels: 61/450 – 65/450

Quick Answer

Day 13 covers list methods. append() adds to the end, insert() adds at a position, remove() deletes by value, pop() takes out the last item, and sort() changes the list itself and returns None.

What You Will Learn

Code

nums = [10, 20, 30]
nums.append(40)
nums.insert(0, 5)
nums.remove(20)
last = nums.pop()
print(nums, "popped:", last)
nums.extend([1, 2])
print(nums)
nums.sort()
print(nums)
print(list(dict.fromkeys([3, 1, 3, 2])))

Output

[5, 10, 30] popped: 40
[5, 10, 30, 1, 2]
[1, 2, 5, 10, 30]
[3, 1, 2]

Code Explained, Line by Line

  1. append(40) adds 40 at the end of the list.
  2. insert(0, 5) puts 5 at index 0 and shifts the rest forward.
  3. remove(20) deletes the first item with value 20.
  4. pop() removes and returns the last item.
  5. extend([1, 2]) adds two items; append([1, 2]) would add one list as a single item.
  6. sort() sorts the list in place and returns None, so nums = nums.sort() makes nums None.
Common Mistake: nums = nums.sort() is a classic bug: sort() returns None and changes the list itself. Just call nums.sort().

Real-Life Use

Removing duplicates, sorting scores and managing carts all use these list methods.

Practice Task: Remove duplicates from a list and show the difference between append and extend with a small example.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. What does [1, 2].append([3, 4]) give?

Q2. What does sort() return?

Q3. What does pop() return?

Today's 5 Reels (from the 90-Day Plan Excel)

61/450Conceptappend, insert, remove
62/450Live demopop, sort, reverse demo
63/450Common mistakesort() None return karta
64/450QuizQuiz: list se duplicates
65/450Interview / real lifeInterview: append vs extend
← Day 12Day 14 →