create the node class class nodedef __init__(selfdata)self data data self next none self prev none create the doubly linked list class class doubly_linked_listdef __init__(self)self head none define the push method to add elements at the begining def push(selfnewval)newnode node(newvalnewnode next self head if self head is not noneself head prev newnode self head newnode define the append method to add elements at the end def append(selfnewval)newnode node(newvalnewnode next none if self head is nonenewnode prev none self head newnode return last self head while (last next is not none)last last next last next newnode newnode prev last return define the method to print