Python Program to remove an element from a list (Using slice operator)

bookmark

# Python program to remove an element from a list using slice operator  
my_list = [1, 2, 3, 4, 5]  
index_to_remove = 2  # Index of element to remove  
my_list = my_list[:index_to_remove] + my_list[index_to_remove + 1:]  
print(my_list)    


Output:

[1, 2, 4, 5]