Is it possible to print a substitute SymPy expression without calculation? I want to print both substituted express and result.
e.g.
x = Symbol('x')
expr = x**2
pprint(expr) # this prints expression
result = expr.subs({x:2})
print(result) # this print result 4
How can I print the "middle result", the expression 2**2?
You can pass in UnevaluatedExpr for this purpose, as shown below:
result = expr.subs(x, UnevaluatedExpr(2))
print(result) # prints 2**2
result = result.doit()
print(result) # prints 4
Documentation: Prevent expression evaluation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With