data structuresalgorithmsand code simplification saying with as xwith as ystatements be aware that if an inner context manager traps and suppresses an exceptionno exception information is passed along to the outer managers closing(objectcreates context manager that automatically executes object close(when execution leaves the body of the with statement the value returned by the with statement is the same as object functools the functools module contains functions and decorators that are useful for creating higher-order functionsfunctional programmingand decorators partial(function [*args [**kwargs]]creates function-like objectpartialthat when calledcalls function with positional arguments argskeyword arguments kwargsand any additional positional or keyword arguments that are supplied additional positional arguments are added to the end of argsand additional keyword arguments are merged into kwargsoverwriting any previously defined values (if anya typical use of partial(is when making large number of function calls where many of the arguments are held fixed for examplefrom functools import partial mybutton partial(buttonrootfg="black",bg="white",font="times",size=" " mybutton(text="ok"calls button(with text="okand all of the mybutton(text="cancel"additional arguments supplied to partial(above mybutton(text="restart"an instance of the object created by partial has the following attributesitem description func args function that is called when is called tuple containing the leftmost positional arguments supplied to func when called additional positional arguments are concatenated to the end of this value dictionary containing the keyword arguments supplied to func when called additional keyword arguments are merged into this dictionary keywords use caution when using partial object as stand-in for regular function the result is not exactly the same as normal function for instanceif you use partial(inside class definitionit behaves like static methodnot an instance method reduce(functionitems [initial]applies functionfunctioncumulatively to the items in the iterable items and returns single value function must take two arguments and is first applied to the first two items of items this result and subsequent elements of items are then combined one at time in similar manneruntil all elements of items have been consumed initial is an optional starting value used in the first computation and when items is lib fl ff