condition1 = "((2=2) or (3=1)) and (1=1)"condition2 = "((2=3) or (1=1)) and (4=5)"
以上两个条件分别给出了输出True和False.
更多解释:
condition1的工作原理,
if ((2==2) or (3==1)) and (1==1): Return Trueelse: Return False
condition1的输出:True
condition2的工作原理,
if ((2==3) or (1==1)) and (4==5): Return Trueelse: Return False
condition2的输出:True
更新:
对不起朋友,
我有条件字符串,如上面的条件1和条件2.
我想在将条件解析为字符串时执行函数,并且该函数执行如if – else并返回布尔值
请帮忙…
谢谢
Chintan
In [1]: condition1 = "((2=2) or (3=1)) and (1=1)" ...: condition2 = "((2=3) or (1=1)) and (4=5)" ...: In [2]: eval(condition1.replace('=','=='))Out[2]: TrueIn [3]: eval(condition2.replace('=','=='))Out[3]: False总结
以上是内存溢出为你收集整理的python – 获取条件字符串返回值:True或False全部内容,希望文章能够帮你解决python – 获取条件字符串返回值:True或False所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)