Solution (source code)

= Solution

For a real <random variable> $X$ with finite <expectation> $\mu=\mathbb E X$, its <variance> is
$$
\boxed{\operatorname{Var}(X)=\mathbb E[(X-\mu)^2].}
$$
When the <second moment> is finite, expansion and <linearity of expectation> give $\operatorname{Var}(X)=\mathbb E[X^2]-\mu^2$. The definition also permits infinite <variance> when the <expectation> is finite but the <second moment> is infinite.