简体   繁体   English

在python中存储和处理逻辑表达式的任何方式

[英]Any way to store and work on logical expressions in python

I want to store and work (access each literal from an expression and further) on logical expressions like ((A /\\ B) / C) in python. 我想在python中像((A / \\ B)/ C)这样的逻辑表达式上存储和工作(从表达式中访问每个文字,并进一步访问)。 Can anyone please suggest a data structure or a way to do it using classes. 任何人都可以建议使用类的数据结构或方法。 I am new to python so please explain your answer in detail. 我是python的新手,所以请详细说明您的答案。

There is a lib named sympy. 有一个名为sympy的库。 Maybe you can have a try 也许可以尝试一下

from sympy import *
a,b,c = symbols('a b c')
(a & b) | c
Or(And(a, b), c)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM