example:

exec:执行字串语句

>>> l=[12,3,4,4]
>>> s = 'l.append(10)'
>>> exec(s)
>>> s
'l.append(10)'
>>> l
[12, 3, 4, 4, 10]
>>>

 

eval:让字串变成与之对应的变量名

>>> str = 'good'
>>> good = 'hello!world'
>>> eval(str)
'hello!world'
>>> good
'hello!world'

 

 

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-01-08
  • 2021-09-14
  • 2022-03-10
  • 2022-01-28
相关资源
相似解决方案