小编van*_*der的帖子

在Python中评估数学表达式

我想将一个给定的数学表达式标记为一个解析树,如下所示:

((3 + 4 - 1) * 5 + 6 * -7) / 2

                          '/'
                        /     \
                       +        2
                    /     \
                  *         *
                /   \     /   \
               -     5   6     -7
             /   \
            +     1
          /   \
         3     4
Run Code Online (Sandbox Code Playgroud)

有没有纯Python方法来做到这一点?就像将字符串作为字符串传递给Python然后像上面提到的那样返回树.

谢谢.

python math parsing binary-tree mathematical-expressions

11
推荐指数
1
解决办法
4712
查看次数