inserting into heap inserting data element to heap always adds the element at the last index butyou can apply heapify function again to bring the newly added element to the first index only if it smallest in value in the below example we insert the number import heapq [ , , , , , covert to heap heapq heapify(hprint(hadd element heapq heappush( , print(hwhen the above code is executedit produces the following result[ [ removing from heap you can remove the element at first index by using this function in the below examplethe function will always remove the element at the index position import heapq [ , , , , , create the heap heapq heapify(hprint(hremove element from the heap heapq heappop(hprint(hwhen the above code is executedit produces the following result[ [