# Recursive definition for the length of a string?

I found a couple of answers online but I don't quite understand why the answer is right:

1. The length of a string is:
If a string has no characters, then its length is 0.
Otherwise, the length of the string is 1 + length of the tail

• Don't use images as main content of your post. This makes your question impossible to search and inaccessible to the visually impaired; we don't like that. Please transcribe text and mathematics (note that you can use LaTeX) and don't forget to give proper attribution to your sources! – dkaeae Apr 29 at 18:47

Strings are concatenations of characters. Hence, any non-empty string $$w$$ has a first character $$x$$ and can be written as $$w = x w'$$, where $$w'$$ is the tail string. It follows from the definition of a string's length that $$|w| = |x w'| = |x| + |w'| = 1 + |w'|$$.