We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Recursion Review

– xkcd

I hate explaining jokes, but in case you don't get the comic: The joke is that the characters within the Dungeons and Dragons game are also playing their own Dungeons and Dragons game. Maybe their characters' game of DnD also has characters playing DnD, and so on, recursively forever.

Another Example

def print_chars(word: str, i: int) -> None:
    if i == len(word):
        return
    print(word[i])
    print_chars(word, i + 1)


print_chars("Hello", 0)
# H
# e
# l
# l
# o