0% found this document useful (0 votes)
2 views7 pages

List Methods in Python

The document provides an overview of lists in Python, describing them as ordered, mutable collections that can hold different data types. It lists common methods for manipulating lists, including append(), insert(), remove(), pop(), sort(), reverse(), index(), count(), and extend(). Each method is briefly explained with examples demonstrating their usage.

Uploaded by

narsingojurishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

List Methods in Python

The document provides an overview of lists in Python, describing them as ordered, mutable collections that can hold different data types. It lists common methods for manipulating lists, including append(), insert(), remove(), pop(), sort(), reverse(), index(), count(), and extend(). Each method is briefly explained with examples demonstrating their usage.

Uploaded by

narsingojurishi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

List Methods in Python

-BY
24B81A05MB
Introduction to Lists:
1.Lists are sequence data type
2.Lists are ordered
3.Mutable collections of items in Python.
4.Can store elements of different data types.
5.Defined using square brackets: e.g., my_list = [1, 2, 'apple', 4.5]
Common List Methods:
• append() – Add an element to the end of the list
my_list = [10, 20, 30]
my_l ist.append(40) # [10, 20, 30, 40]

• insert() – Insert element at a specific index


my_list.insert(1, 15) # [10, 15, 20, 30, 40]

• remove() – Remove first matching element


my_list.remove(20) # [10, 15, 30, 40]

• pop() – Remove element at index (default last)


my_list.pop() # [10, 15, 30]
sort() – Sort the list
my_list.sort() # [10, 15, 30]

reverse() – Reverse the list order


my_list.reverse() # [30, 15, 10]

index()-Returns the position of the first occurrence of a specified value.


count():
Returns the number of times a value appears in the list.

extend():
Adds elements from another iterable (like a list) to the end of the current list.
TQ

You might also like