list in python and list functions

 list in python and list functions



#list allows to change element of any index

mylist=["khana","paani","daal","bhat","sabji","chana","matar","pulao"] #elements list

print(mylist) #print all elements of list
print(mylist[5]) #print 5th element of list

numlist=[1,5,60,84,54]
print(numlist)

#slicing
print(numlist[::-1]) #reverse the list
print(mylist[::-1]) #reverse the list

#list functions
print("minimum element of numlist :",min(numlist)) #returns the minimum element of number list
print("maximum element of numlist :",max(numlist)) #returns the maximum element of number list
mylist.sort() #sort the list elements alphabetical order
numlist.sort(reverse=True) #sort the list in decreaasing order numerically
print(mylist)
print(numlist)
numlist.append(900) #appends given element in last position of list
print(numlist)
numlist.pop() #deletes last element of list
print(numlist)
numlist.insert(4,99) #inserting element '99' in 4th position
print(numlist)
numlist.remove(99) #remove the given element from the list
print(numlist)

#changing value of any index in list
mylist[0]="sevpuri"
print(mylist)

Comments