发布时间:2019-09-11 07:46:09编辑:auto阅读(2113)
x = 1
result = "x+1"
result = eval(result)
print(result)
》》2
Python3中字符串不能计算结果,eval函数将字符串当成有效Python表达式来求值,并返回计算结果。
与之对应的repr函数,它能够将Python的变量和表达式转换为字符串表示
repr(x+1)
上一篇: Python:线程、进程与协程(7)——
下一篇: 53. Python 爬虫(2)
48013
46628
37572
34928
29489
26157
25092
20117
19745
18218
5924°
6584°
6088°
6088°
7202°
6033°
6124°
6592°
6561°
7943°