AI Features

Solution Review: Length of a String

This review provides a detailed analysis of the solution to find the length of a string recursively.

We'll cover the following...

Solution: Using Recursion

Python 3.5
def recursiveLength(testVariable) :
# Base Case
if (testVariable == "") :
return 0
# Recursive Case
else :
return 1 + recursiveLength(testVariable[1:])
# Driver Code
testVariable = "Educative"
print (recursiveLength(testVariable))

Explanation

The base case for this solution will test for an empty string "". If the string is empty we return 0 ...