[ANSWERED] Task using boolean types | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[ANSWERED] Task using boolean types

Let's say I have a string str that contains a logical formula. If i know the formula I just do print((True or False) and True) But if I have only a string that contains the formula like str = "(True or False) and True)" How to convert a string to a command, a boolean variable? bool() wont work, it is sth different.

22nd Sep 2017, 8:43 PM
Alex Snaidars
Alex Snaidars - avatar
1 Answer
+ 9
You could use eval() for that: str = "(True or False) and True)" print(eval(str)) >>> True
22nd Sep 2017, 8:45 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar