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. Identification of the nonrecursive case, called the base case, is important to make sure that the recursive calls work correctly. Finally, 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.
Key Terms ...
Get Python Programming in Context, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.