Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以将字符串转换为可计算的操作
我想做到这一点:
>>> import math >>> operation = "10/2*6 + math.sqrt(42)" >>> compute(operation) 36.48074069840786
eval会为你做的。
eval
>>> import math >>> operation = "10/2*6 + math.sqrt(42)" >>> eval(operation) 36.48074069840786