Write a program to perform the below operations on the list : ● Create a list. ● Add/Remove an item to/from a list. ● Get the number of elements in the list. ● Access elements of the list using the index. ● Sort the list. ● Reverse the list.


 list1 = [1,2,3,4,5,6]
print(list1)

#adding value
print(list1)
list1.append(7)
print(list1)

# removing value
list1.remove(7)
list1.pop(2)
print(list1)

#checking elements of list
print("There are",len(list1),"Elements in the list")

# printing by index
print("Value of list at index 0 is :",list1[0])

# created list for sorting
list2 = [2,0,1,67,5,4]

#list get sorted
list2.sort()
print(list2)

#list get reversed
list2.sort(reverse=True)
print(list2)


Output:

[1, 2, 3, 4, 5, 6]

[1, 2, 3, 4, 5, 6]

[1, 2, 3, 4, 5, 6, 7]

[1, 2, 4, 5, 6]

There are 5 Elements in the list

Value of list at index 0 is : 1

[0, 1, 2, 4, 5, 67]

[67, 5, 4, 2, 1, 0]

Comments