2. Given a positive integer $k(1 \leqslant k \leqslant 9)$. Let $\underset{n \uparrow \cdots k}{k k \cdots}$ denote the $n$-digit positive integer in decimal notation where each digit is $k$. If for any positive integer $n$, the function $f(x)$ satisfies
$$
f(\underbrace{\overline{k k \cdots k}}_{n \uparrow})=\underbrace{\overline{k k \cdots k}}_{2 n \uparrow},
$$

then the expression for the function $f(x)$ is
2. $f(x)=\frac{9}{k} x^{2}+2 x$.

Notice that
$$
\begin{array}{l}
\underbrace{k k \cdots k}_{n \uparrow}=k\left(10^{n-1}+10^{n-2}+\cdots+10+1\right) \\
=\frac{k}{9}\left(10^{n}-1\right)
\end{array}
$$

Let $x=\frac{k}{9}\left(10^{n}-1\right)$, i.e., $10^{n}=\frac{9}{k} x+1$.
$$
\begin{array}{l}
\text { Hence } \frac{\overline{k k \cdots k}}{2 n \uparrow}=\frac{k}{9}\left(10^{2 n}-1\right) \\
=\frac{k}{9}\left(10^{n}-1\right)\left(10^{n}+1\right)=x\left(\frac{9}{k} x+2\right) \\
=\frac{9}{k} x^{2}+2 x .
\end{array}
$$

Thus, $f(x)=\frac{9}{k} x^{2}+2 x$.