What is SymPy’s .evalf() function?

Sympy, a powerful Python library for symbolic mathematics, offers a myriad of functions to explore and utilize. Among these, the .evalf() method stands out as a key tool for converting symbolic expressions into numerical approximations.

Assume we have a mathematical expression with a π\pi symbol. The .evalf() method takes the symbolic expression and computes an approximation of its numerical value. For example, we have the expression cos(π/4)cos(\pi/4). Without using the .evalf() method, Python would just tell us it's cos(π/4)cos(\pi/4). But when we apply the .evalf() method, it will compute the numerical approximation of this expression, which is approximately 0.707106781186548.

Syntax

Here’s the syntax of the .evalf() method:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Note: sympify(expr) is an expression that we want to convert to its numerical approximations.

Code examples

Let’s see a code example to understand how this method works.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
  • Line 3: We define a symbolic variable.

  • Line 6: We define a symbolic expression.

  • Line 9: We use the .evalf() method to get the numerical value.

The .evalf() method computes the numerical approximation for complex numbers as well. Let’s see the code example for complex numbers:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Conclusion

SymPy’s .evalf() function serves as a valuable tool for obtaining numerical approximations of symbolic expressions, including those involving complex numbers.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved