from sympy import symbols, diff # Define the symbol x = symbols('x') # Define the function f = x**3 + 2*x**2 + 3*x + 4 # Calculate the derivative derivative = diff(f, x) # Print derivative print(derivative) >>> 3*x**2 + 4*x + 3