SymPy - evalf() function


This function evaluates a given numerical expression upto a given floating point precision upto 100 digits. The function also takes subs parameter a dictionary object of numerical values for symbols. Consider following expression

>>> from import r 
>>> expr=pi*r**2 
>>> expr

The above code snippet gives an output equivalent to the below expression −


To evaluate above expression using evalf() function by substituting r with 5

>>> expr.evalf(subs={r:5})

The above code snippet gives the following output −


By default, floating point precision is upto 15 digits which can be overridden by any number upto 100. Following expression is evaluated upto 20 digits of precision.

>>> expr=a/b 
>>> expr.evalf(20, subs={a:100, b:3})

The above code snippet gives the following output −