简体   繁体   中英

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. 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.

There is a lib named 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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