====================LISTS===================================
#create list
x=[10,20,30,40,50]
print("list is :",x)
print(" ")
print(" ")
#access the list
y=["apple","banana","orange","mango"]
print("list is :",y)
print("y[0] is :",y[0])
print("y[1] is :",y[1])
print("y[3] is :",y[3])
print(" ")
print(" ")
#replace the list with difference values
y=["apple","banana","orange","mango"]
print("before replace values list is :",y)
#create list
x=[10,20,30,40,50]
print("list is :",x)
print(" ")
print(" ")
#access the list
y=["apple","banana","orange","mango"]
print("list is :",y)
print("y[0] is :",y[0])
print("y[1] is :",y[1])
print("y[3] is :",y[3])
print(" ")
print(" ")
#replace the list with difference values
y=["apple","banana","orange","mango"]
print("before replace values list is :",y)
y[0]="jackfruit"
print("y[0] replace with jackfruit :",y[0])
y[3]="watermelon"
print("y[3] replace with watermelon :",y[3])
print("after replace values list is :",y)
print(" ")
print(" ")
#loop through a list
list1=[1000,2000,"prabhu",5555,"tarak"]
print("loop list1 is :",list1)
for x in list1:
print(x)
print(" ")
print(" ")
#check item in list
list2=[900,9797,67868,100,"prabhu"]
print("loop list2 is :",list2)
print(" ")
#check item in list
list2=[900,9797,67868,100,"prabhu"]
print("loop list2 is :",list2)
if "prabhu" in list2:
print("yes, given item prabhu is avaialbe ")
else:
print(" given item prabhu is NOT avaialbe ")
print(" ")
print(" ")
#append new item in list
list3=[900,9797,67868,100,"prabhu"]
print("before append new values in list3 is :",list3)
list3.append("sandeep")
list3.append(999999)
print("after append new values in list3 is :",list3)
print(" ")
print(" ")
#append new values in given index
list3=[900,9797,67868,100,"prabhu"]
print("before insert new values in list3 is :",list3)
list3.insert(1,"welcome")
list3.insert(3,"xxxxxxx")
print("after insert new values of 1,3 in list3 is :",list3)
print(" ")
print(" ")
#remove an item in given index
list4=[900,9797,67868,100,"prabhu"]
print("before delete values in list4 is :",list4)
print(" ")
list4.remove(67868)
print("after remov(67868) value :",list4)
print(" ")
list4.pop()
print("after remove last value in list is pop():",list4)
print(" ")
del list4[1]
print("after deleitng values based on del index4[1]:",list4)
print(" ")
list4.clear()
print("after done empty list4.clear():",list4)
print(" ")
OUTPUT
list is : [10, 20, 30, 40, 50]
list is : ['apple', 'banana', 'orange', 'mango']
y[0] is : apple
y[1] is : banana
y[3] is : mango
before replace values list is : ['apple', 'banana', 'orange', 'mango']
y[0] replace with jackfruit : jackfruit
y[3] replace with watermelon : watermelon
after replace values list is : ['jackfruit', 'banana', 'orange', 'watermelon']
loop list1 is : [1000, 2000, 'prabhu', 5555, 'tarak']
1000
2000
prabhu
5555
tarak
loop list2 is : [900, 9797, 67868, 100, 'prabhu']
yes, given item prabhu is avaialbe
before append new values in list3 is : [900, 9797, 67868, 100, 'prabhu']
after append new values in list3 is : [900, 9797, 67868, 100, 'prabhu', 'sandeep', 999999]
before insert new values in list3 is : [900, 9797, 67868, 100, 'prabhu']
after insert new values of 1,3 in list3 is : [900, 'welcome', 9797, 'xxxxxxx', 67868, 100, 'prabhu']
before delete values in list4 is : [900, 9797, 67868, 100, 'prabhu']
after remov(67868) value : [900, 9797, 100, 'prabhu']
after remove last value in list is pop(): [900, 9797, 100]
after deleitng values based on del index4[1]: [900, 100]
after done empty list4.clear(): []