Program for length of a string using recursion | Python program to calculate length of a string using recursion ; Function to calculate length ; if we reach at the end of the string ; Driver Code
str = " GeeksforGeeks " NEW_LINE def string_length ( str ) : NEW_LINE INDENT if str == ' ' : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 + string_length ( str [ 1 : ] ) NEW_LINE DEDENT DEDENT print ( string_length ( str ) ) NEW_LINE