newnode node(newvalnewnode next self head if self head is not noneself head prev newnode self head newnode define the insert method to insert the element def insert(selfprev_nodenewval)if prev_node is nonereturn newnode node(newvalnewnode next prev_node next prev_node next newnode newnode prev prev_node if newnode next is not nonenewnode next prev newnode define the method to print the linked list def listprint(selfnode)while (node is not none)print(node data)last node node node next dllist doubly_linked_list(dllist push( dllist push( dllist push( dllist insert(dllist head next dllist listprint(dllist headwhen the above code is executedit produces the following result appending to doubly linked list appending to doubly linked list will add the element at the end