How to evaluate python string boolean expression using eval()?
问题 I get boolean expression like below : string = '!True && !(True || False || True)' I know eval('1+2') returns 3 . But when I am executing eval(string) it is throwing me error as in invalid syntax. Is there any other way I can execute the above expression? 回答1: None of ! , && and || are valid Python operators; eval() can only handle valid Python expressions. You'd have to replace those expressions with valid Python versions; presumably ! is not , && is and , and || is or , so you could just