Irfan Khan
0
Q:

recursively count string

def length(s): 
   if not s:  # test if there are no more characters in the string
      return 0
   else:  # maintain a count by adding 1 each time you return
          # get all but the first character using a slice
      return 1 + length( s[1:] )
0

New to Communities?

Join the community