What are the methods of list in python?

Description

To see the major methods of list in python3.

Append

It add the element in to the list.

Eg:list.append(element).

 Insert

It used to add the new element in a

corresponding  position.

Eg.list.insert(element index position).

Pop

It used to delete corresponding index

of the object to  be removed from the list.

Eg.list.pop(1).

 Remove

This method does not return any value

but removes  the given object from the list

Eg.list.remove(element).

Reverse

Its reverse the given element in a list.

Eg.list.reverse().

#Take sample list

list1=[‘sathish’,’sangeetha’,’venkat’,
‘sheela’,’sudhakar’,23,24,25,21,21]

#append the list

print(“**************Append method demo”)

print(“Actual list is\n”,list1)

print(“After append the list”)

list1.append(‘Loganath’)

print(list1)

#insert the list

print(“**************Insert method demo\n”)

print(“After insert the list”)

list1.insert(2,’mano’)

print(list1)

#pop the list

print(“**************Pop method demo\n”)

list1.pop(1)

print(“After pop the list”)

print(list1)

#remove from the list

print(“**************Remove method demo\n”)

list1.remove(‘venkat’)

print(“After remove the list”)

print(list1)

#make reverse of a list

print(“**************Reverse method demo\n”)

list1.reverse()

print(“After reverse the list”)

print(list1)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit