Python

Python List Methods & Slicing πŸ”₯ | append(), remove(), pop(), sort() | Python Lesson 15

Published

About this video

Learn Python List Methods, Slicing and Useful List Patterns step by step with PEARL INSTITUTE BATALA.

In Lesson 15 of our Python + Machine Learning Practical Course, you will learn how to efficiently add, remove, slice, sort and process Python lists using commonly used methods and practical patterns.

This lesson is explained in easy Hindi/Hinglish with practical examples, common mistakes and a quick practice question.

βœ… In this lesson you will learn:

β€’ Quick Revision of Python Lists
β€’ What are List Methods?
β€’ append() – Add an Item at the End
β€’ insert() – Add an Item at a Specific Index
β€’ remove() – Remove an Item by Value
β€’ pop() – Remove an Item by Index
β€’ Difference Between remove() and pop()
β€’ Python List Slicing
β€’ list[start:stop] Syntax
β€’ Slice from the Beginning
β€’ Slice to the End
β€’ Creating a Shallow Copy using [:]
β€’ Membership Testing using in
β€’ Looping Through Lists
β€’ sort() Method
β€’ reverse() Method
β€’ Sorting in Descending Order
β€’ Practical Top Scores Example
β€’ Common List Method Mistakes
β€’ Quick Practice Question

πŸ’» append() Example

courses = ["Python", "Java"]

courses.append("Web")

Output:

["Python", "Java", "Web"]

πŸ“Œ insert() Example

courses.insert(1, "Java")

This inserts the value at the selected index.

πŸ”₯ remove() vs pop()

Remember this simple rule:

remove() = Value
pop() = Index

Example:

skills.remove("Java")

removes the value "Java".

Whereas:

skills.pop(1)

removes the item at index 1.

βœ‚οΈ Python List Slicing

Example:

numbers = [10, 20, 30, 40, 50]

numbers[1:4]

Output:

[20, 30, 40]

Important rule:

Start index is included.
Stop index is excluded.

Useful slicing patterns:

numbers[:3] β†’ From beginning to index 3

numbers[2:] β†’ From index 2 to the end

numbers[:] β†’ Create a shallow copy of the list

πŸ”Ž Membership Testing

"Python" in courses

Output:

True

πŸ” Loop Through a List

for course in courses:

print(course)

πŸ“Š Sorting Lists

marks.sort()

arranges values in ascending order.

marks.reverse()

reverses the current order.

For descending sorting:

scores.sort(reverse=True)

πŸ† Practical Example

You can combine sorting and slicing to find the top three scores:

scores.sort(reverse=True)

top_three = scores[:3]

This is a very useful pattern for real data-processing tasks.

⚠️ Common Beginner Mistake

If you want to remove the item at index 1, do not use:

numbers.remove(1)

because remove() searches for the actual value 1.

Use:

numbers.pop(1)

to remove by index.

🎯 Perfect For:

Python Beginners
Coding Beginners
BCA / B.Sc. IT / MCA Students
School & College Students
Programming Students
Machine Learning Beginners
Computer Course Students
Students Learning Python from Scratch

πŸ€– Machine Learning Connection

List methods and slicing are useful while preparing small collections of values before moving to larger data structures such as NumPy arrays and Pandas DataFrames.

πŸ“š Course: Python + Machine Learning Practical Course
πŸŽ“ Lesson 15: List Methods, Slicing and Useful List Patterns

🏫 PEARL INSTITUTE BATALA

πŸ“ Near Bus Stand, Jalandhar Road, BATALA
πŸ“ž Call / WhatsApp: 7814976999
🌐 www.PEARLINSTITUTE.in
πŸ‘©β€πŸ« Institute Head: Mrs Sonika Malhotra

πŸ‘‰ Subscribe to continue learning Python step by step.

πŸ”œ Next Lesson: Dictionary Methods and Nested Data Structures

Watch the original on YouTube