0

I have a function that returns a string that can be interpreted as a Boolean

def foo():
    return "not(True and False)"

How can I return the actual Boolean value, in this case True?

  • Yes. I want not(True) to be False, (True or False) to be True. Whatever the results would be If the quotes would not be there. –  Feb 11 '20 at 04:20
  • I think eval() will probably already work, have you tried using this function? – ccl Feb 11 '20 at 04:21
  • 1
    Why does your function have such a strange return value? The best approach is likely to change the function. – user2357112 Feb 11 '20 at 04:22
  • Python 3, I want to return the actual Boolean value. –  Feb 11 '20 at 04:22
  • 1
    _I have a function that returns a string that can be interpreted as a Boolean_ What, why? – AMC Feb 11 '20 at 04:30

1 Answers1

0

You could use eval:

def foo():
    return eval("not(True and False)")

Even tho it is virtually the only solution, but it is still not safe.

Check this link for why it is not safe.

FoviBot
  • 60
  • 4