Search⌘ K
AI Features

Solution Review: Length of a String

Understand how to determine a string's length recursively by testing an empty string as the base case and reducing the string step-by-step. This lesson helps you break down the problem, implement the recursive function, and visualize the process to strengthen your recursion skills with strings.

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 ...