from sympy import * x = symbols('x') expr = (2*x+1/x**2)**4 expr_expanded = expand(expr) expr_expanded
expr_expanded.coeff(x)