Python Tutorial

List Methods in Python Explained With Example

Table of Contents

  • Understanding List Methods in Python
  • Quiz!

Understanding List Methods in Python

All the Python List methods are as listed below:

1. clear(): To delete all items from the list.

Code:

f = ["python", "web", "wscube"]

f.clear()

print(f)
Output:
[]

https://youtu.be/7laJ_UTxWwc

2. copy(): To return a shallow copy of the list.

Code:

f = ["python", "web", "wscube"]

X = f.copy()

print(X)
Output:
["python", "web", "wscube"]

3. count(): To return the count of the element in the list.

Code:

f = ["python", "web", "wscube"]

x = f.count("web")

print(x)

Output:

1

4. extend(): This function is used to ad iterable items to the end of the list.

Code:

f = ["python", "web", "wscube"]

cars = ['Ford', 'BMW', 'Volvo']

x= f.extend(cars)

print(x)
Output:
["python", "web", "wscube", ['Ford', 'BMW', 'Volvo'] ]

5. index(): To return the index of the element in the list.

Code:

f = ["python", "web", "wscube"]

x=  f.index("web")

print(x)
Output:
2

6. reverse(): Reverses the list.

Code:

f = ["python", "web", "wscube"]

f.reverse()

print(f)
Output:
["wscube", "web","python"]

7. sort(): Sorts elements of a list

Code:

c = [1,3,2,7,5]

c.sort()

print(c)
Output:
[1, 2, 3, 5, 7]

https://youtu.be/8O08w9__0nw

https://youtu.be/r6CcB5BZt0k

https://youtu.be/KQDI4-Mc_c0

Quiz!

quiz-img
Did you find this article helpful?