Recursion for Beginners: A Beginner's Guide to Recursion
By Al Sweigart

Between unintelligible algorithms and beautiful fractal artwork, recursion has an intimidating reputation. But the underlying ideas behind it are simple. This tutorial presents a quick intro of recursive code, Python's features for handling recursion, and drawing fractals with the turtle module. If you've ever thought "recursion is confusing", this tutorial is for you.

Saturday 5:05 p.m.–5:35 p.m.

Recursion has an intimidating reputation for being the advanced skill of coding sorcerers. But in this tutorial we look behind the curtain of this formidable technique to discover the simple ideas under it.

Through live coding demos in the interactive shell, we'll answer the following questions:

  • What is recursion, and when is it a good idea and bad idea to use it?
  • What's a stack, the call stack, and a stack overflow?
  • What are all the confusing ways that recursion is commonly taught?
  • Do some problems require recursion? Can recursion do anything a loop can't?
  • What is memoization, and how does functools.lru_cache work?
  • How do I draw that cool-looking recursive fractal artwork with Python's turtle module?

Beginners will be able to follow this talk. All that is required is a willingness to learn, and a willingness to have the willingness to learn, and a willingness to have the willingness to have the willingness to learn, and... so on.

Al Sweigart

Al Sweigart is a software developer and the author of Automate the Boring Stuff with Python, Coding with Minecraft, Cracking Codes with Python, Invent Your Own Computer Games with Python, and Making Games with Python & Pygame. These books are freely available under a Creative Commons license at

Al enjoys haunting coffee shops, writing educational materials, cat whispering, and making useful software. He lives in San Francisco.