Example 8 Let $P(x)$ be a polynomial of degree $2n$, $P(0)=P(2)=\cdots=P(2n)=0, P(1)=$ $P(3)=\cdots=P(2n-1)=2, P(2n+1)=-30$, find $n$.


Let $f(x) = P(x) - 1$, then $f(k) = (-1)^{k+1}, k = 0, 1, \cdots, 2n, f(2n+1) = -31$. Consider the Lagrange formula, and note the $k$-th term
$$
\begin{array}{l}
f_{k}(x) = \prod_{\substack{i \neq k \\
0 \leqslant i \leqslant 2n}} \frac{x-i}{k-i} \cdot f(k), \\
\therefore \quad f_{k}(2n+1) = \frac{(2n+1)!}{(2n+1-k)} \cdot \frac{(-1)^{k+1}}{k!(2n-k)!(-1)^{2n-k}} = -C_{2n+1}^{k} .
\end{array}
$$

And $f(2n+1) = \sum_{k=1}^{2n+1} f_{k}(2n+1) = -\sum_{k=1}^{2n+1} C_{2n+1}^{k} = 1 - 2^{2n+1} = -31$, solving for $n$ gives $n = 2$, which is the desired result.