how much error-checking to perform within function is matter of debate checking the type and value of each parameter demands additional execution time andif taken to an extremeseems counter to the nature of python consider the built-in sum functionwhich computes sum of collection of numbers an implementation with rigorous error-checking might be written as followsdef sum(values)if not isinstance(valuescollections iterable)raise typeerrorparameter must be an iterable type total for in valuesif not isinstance( (intfloat))raise typeerrorelements must be numeric total totalv return total the abstract base classcollections iterableincludes all of python' iterable containers types that guarantee support for the for-loop syntax ( listtupleset)we discuss iterables in section and the use of modulessuch as collectionsin section within the body of the for loopeach element is verified as numeric before being added to the total far more direct and clear implementation of this function can be written as followsdef sum(values)total for in valuestotal total return total interestinglythis simple implementation performs exactly like python' built-in version of the function even without the explicit checksappropriate exceptions are raised naturally by the code in particularif values is not an iterable typethe attempt to use the for-loop syntax raises typeerror reporting that the object is not iterable in the case when user sends an iterable type that includes nonnumerical elementsuch as sum([ oops ]) typeerror is naturally raised by the evaluation of expression total the error message unsupported operand type(sfor +'floatand 'strshould be sufficiently informative to the caller perhaps slightly less obvious is the error that results from sum(alpha beta ]it will technically report failed attempt to add an int and strdue to the initial evaluation of total alpha when total has been initialized to in the remainder of this bookwe tend to favor the simpler implementations in the interest of clean presentationperforming minimal error-checking in most situations