Python Program to append element in the list ( insert(index, elmt))

bookmark

list1 = [10, 20, 30, 40, 50]  
  
print('Current Numbers List: ', list1)  
  
el = list1.insert(3, 77)  
print("The new list is: ",list1)  
  
n = int(input("enter a number to add to list:\n"))  
  
index = int(input('enter the index to add the number:\n'))  
  
list1.insert(index, n)  
  
print('Updated Numbers List:', list1)  


Output:

Current Numbers List:  [10, 20, 30, 40, 50]
The new list is:  [10, 20, 30, 77, 40, 50]
enter a number to add to list:
 45
enter the index to add the number:
1
Updated Numbers List: [10, 45, 20, 30, 77, 40, 50]