append() function:
This function is used to append any value at the end of the list.
eg
l=[1,2,3]
l.append(4)
print(l) # [1,2,3,4]
pop() function:
It deletes the last value of the list by default.
It returns the value which is deleted by this method.
It raises IndexError if no element found.
l=[10,20,30]
x=l.pop()
print("The deleted element is",x)
print(l) # [10,20]
pop function can also be used to delete any specific value from the list as shown below.
l=[1,2,3]
l.pop(2) #here 2 is the index means 3 will be deleted from the list
print(l) # [1,2]
remove() function:
This function does not return the value it has removed from the list.
It always requires an argument.
It raises ValueError if element is not found in the list.
l=[1,2,3]
l.remove(2)
print(l) # [1,3]
This function is used to append any value at the end of the list.
eg
l=[1,2,3]
l.append(4)
print(l) # [1,2,3,4]
pop() function:
It deletes the last value of the list by default.
It returns the value which is deleted by this method.
It raises IndexError if no element found.
l=[10,20,30]
x=l.pop()
print("The deleted element is",x)
print(l) # [10,20]
pop function can also be used to delete any specific value from the list as shown below.
l=[1,2,3]
l.pop(2) #here 2 is the index means 3 will be deleted from the list
print(l) # [1,2]
remove() function:
This function does not return the value it has removed from the list.
It always requires an argument.
It raises ValueError if element is not found in the list.
l=[1,2,3]
l.remove(2)
print(l) # [1,3]
Be First to Post Comment !
Post a Comment