9.5 Summary
In this chapter, we introduced recursion, a powerful programming technique that allows us to elegantly solve problems by taking advantage of “self-reference.” Fractals are graphically self-referential—that is, they contain smaller versions of themselves. We can implement recursion by simply letting a Python function call itself. Defining the nonrecursive case, called the base case, is important to make sure that the recursive calls work correctly. We explored L-systems, which formally denote fractal behavior using a set of grammar rules. A string of symbols can be produced by repeatedly applying these rules. By interpreting this result string as a series of turtle commands, we can draw a fractal. We also introduced the match statement, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access