What is an Expr in Python AST?

前端 未结 2 1136
盖世英雄少女心
盖世英雄少女心 2021-01-06 07:36

I\'m working on dynamically generating code in Python.

To aid with this, I wrote a helper method which takes in a string of Python code and dumps out the AST. Here\'

2条回答
  •  我在风中等你
    2021-01-06 07:56

    Agreeing with what @BreBarn said:

    "When an expression, such as a function call, appears as a statement by itself (an expression statement), with its return value not used or stored, it is wrapped in this container."

    Since you're using the result of the len function to print, it's not technically an Expression, in the AST sense.

    See this for more info: https://greentreesnakes.readthedocs.org/en/latest/nodes.html#expressions

提交回复
热议问题