Tuesday, November 19, 2019

remove method in python

l1=[10,20,30,40]
print(l1)
l1.remove(20)
print(l1)

output:
[10, 20, 30, 40]
[10, 30, 40]

example 2:

l1=[10,20,30,40,50,60,70]
x=int(input("enter elements to be removed"))
if x in l1:
    l1.remove(x)
    print("removed successfully")
    print(l1)
else:
    print("specified element is not available")

output:
enter elements to be removed10
removed successfully
[20, 30, 40, 50, 60, 70]

enter elements to be removed20
removed successfully
[10, 30, 40, 50, 60, 70]

enter elements to be removed82
specified element is not available


No comments:

Post a Comment

python class topic video