B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP All List Methods in Python with Examples | LiveCodeProgramming
Python Installation First Python Program Control Flow if...else nested if else match-case logical-operators for loops while loops break / continue Functions Defining Functions Function Arguments Function return value Lambda Function Recursion Exception Handling Exception Handling Try Except Else and Finally Raise Exception Custom Exceptions File Handling File in python Read File Write File Append File Delete File Exception Handling

All Python List Methods with Examples

Below are all the built-in list methods in Python with example code and output. This is your complete reference to master Python list functions.

नीचे Python के सभी list methods दिए गए हैं उदाहरण सहित। यह आपकी पूरी list method reference guide है।

Append()

Description: Adds a single element to the end of list.

fruits = ['apple', 'banana', 'cherry']
fruits.append('grape')
print(fruits)
Extend()

Description: Adds elements of another list to current list.

fruits = ['apple', 'banana', 'cherry']
fruits.extend(['mango', 'papaya'])
print(fruits)
Insert()

Description: Inserts an item at a specific index.

fruits = ['apple', 'banana', 'cherry']
fruits.insert(1, 'guava')
print(fruits)
Remove()

Description: Removes first occurrence of value.

fruits = ['apple', 'banana', 'cherry']
fruits.remove('apple')
print(fruits)
Pop()

Description: Removes and returns last item or item at index.

fruits = ['apple', 'banana', 'cherry']
fruits.pop()
print(fruits)
Clear()

Description: Removes all items from list.

fruits = ['apple', 'banana', 'cherry']
fruits.clear()
print(fruits)
Index()

Description: Returns index of first occurrence of value.

fruits = ['apple', 'banana', 'cherry']
fruits.index('banana')
print(fruits)
Count()

Description: Returns count of occurrences of value.

fruits = ['apple', 'banana', 'cherry']
fruits.count('banana')
print(fruits)
Sort()

Description: Sorts the list in ascending order.

fruits = ['apple', 'banana', 'cherry']
fruits.sort()
print(fruits)
Reverse()

Description: Reverses the elements of the list.

fruits = ['apple', 'banana', 'cherry']
fruits.reverse()
print(fruits)
Copy()

Description: Returns a shallow copy of the list.

fruits = ['apple', 'banana', 'cherry']
new_list = fruits.copy()
print(fruits)