Lists are fundamental data structures in Python and are widely used due to their flexibility and ease of use. List in python elements are written under square brackets as shown below.

List in Python

How to create an empty list in python

empty_list=[]  Â

List of elements

a=['apple','orange','mango']

To check length of the list or how many elements are present in the list type

len(a)

Output:3

Because there are 3 elements are in the list.

To print any element in the list

a[0]

Output:'apple'

how to write List in python
1.List in Python

List Methods

Python lists have several built-in methods for common operations.

1. List.append:

To append element in list.

2. List.Pop:

To remove or pop element from a list by its index value.

3. List.Remove:

To remove first occurrence of a value.

4. List.Insert:

To insert object before index

5. List.Reverse:

To reverse the order of a list.

6. List.sort:

To sort a list alphabetically (A to Z) and reverse of it (Z to A).

7. List.index:

To find the index of an object

8. List.clear:

To clear element of list.

9. List.copy:

To create copy of a list.

10. List.count:

To count an element or object occurrence in list.

11. List.extend:

To extend a list.

 

By SC

12 thoughts on “List in Python”

Comments are closed.