Chapter 9: Understanding Code through Abstract Syntax Tree

In this chapter, we will look at what abstract syntax trees are and how to understand the syntax tree of each unit of the Python code we write.

Any programming language is designed with its own syntax, which is used by developers while coding in the language following specific syntax. The interpreter or compiler of a programming language interprets the syntax of the language and compiles or interprets the code and executes it to achieve the desired result.

In Python, an abstract syntax tree (AST) provides an abstract representation of the syntax of the code in the form of a tree. Python has a library named ast that can be used to understand the abstract syntax of the code that we develop. ...

Get Metaprogramming with Python now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.