Python List Methods & Slicing π₯ | append(), remove(), pop(), sort() | Python Lesson 15
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