python' built-in types are already registered with all of these base classes as appropriate alsoby using these base classesit is possible to write programs that are more precise in their type checking here are some examplespull off the last item of sequence if isinstance(xcollections sequence)last [- only iterate over an object if its size is known if isinstance(xcollections iterableand isinstance(xcollections sized)for item in xstatements add new item to set if isinstance(xcollections mutableset) add(itemsee also"classes and object-oriented programming contextlib the contextlib module provides decorator and utility functions for creating context managers used in conjunction with the with statement contextmanager(funca decorator that creates context manager from generator function func the way in which you use this decorator is as follows@contextmanager def foo(args)statements tryyield value except exception as eerror handling (if anystatements when the statement with foo(argsas value appearsthe generator function is executed with the supplied arguments until the first yield statement is reached the value returned by yield is placed into the variable value at this pointthe body of the with statement executes upon completionthe generator function resumes if any kind of exception is raised inside the with-bodythat exception is raised inside the generator function where it can be handled as appropriate if the error is to be propagatedthe generator should use raise to re-raise the exception an example of using this decorator can be found in the "context managerssection of nested(mgr mgr mgrna function that invokes more than one context manager mgr mgr and so on as single operation returns tuple containing the different return values of the with statements the statement with nested( , as ( , )statements is the same as lib fl ff