How can I assign the value of a variable using eval in python?

后端 未结 4 1211
感动是毒
感动是毒 2020-11-27 16:17

Okay. So my question is simple: How can I assign the value of a variable using eval in Python? I tried eval(\'x = 1\') but that won\'t work. It returns a Syntax

4条回答
  •  一向
    一向 (楼主)
    2020-11-27 17:08

    You can actually put exec() command inside eval()

    So your statement would look like eval("exec('x = 1')")

    p.s. this is dangerous

提交回复
热议问题