that simply repeatedly modified the total state variable would be more readableand moreover this function is perfectly reasonable to want to call against sequences of much larger length than howeverin other casesrecursive styleeven over sequential operationsstill expresses algorithms more intuitively and in way that is easier to reason about slightly less trivial examplefactorial in recursive and iterative styledef factorialr( )"recursive factorial functionassert isinstance(nintand > return if < else factorialr( - def factoriali( )"iterative factorial functionassert isinstance(nintand > product while > product * - return product although this algorithm can also be expressed easily enough with running product variablethe recursive expression still comes closer to the "whatthan the "howof the algorithm the details of repeatedly changing the values of product and in the iterative version feels like it' just bookkeepingnot the nature of the computation itself (but the iterative version is probably fasterand it is easy to reach the recursion limit if it is not adjustedas footnotethe fastest version know of for factorial(in python is in functional programming styleand also expresses the "whatof the algorithm well once some higher-order functions are familiarfrom functools import reduce from operator import mul def factorialhof( )return reduce(mulrange( + ) where recursion is compellingand sometimes even the only really obvious way to express solutionis when problem offers itself to "divide and conquerapproach that isif we can do similar computation on two halves (or anywayseveral similarly sized chunksof larger collection in that casethe recursion depth is only (log nof the size of the collectionwhich is unlikely to be (avoidingflow control