Example 3.2.6.

Let \(X\) indicate an event \(A\) which has probability \(p\text{.}\) In Example 3.1.5, we saw \(\E(X) = p\text{.}\) Notice that \(X\) takes the values 0 and 1 (with probabilities \(1 - p\) and \(p\text{,}\) respectively). But \(0^2 = 0\text{,}\) and \(1^1 = 1\text{,}\) so the expected value calculation for \(X^2\) is precisely the same as for \(X\text{!}\)
\begin{align*} \E\left(X^2\right) \amp = 0^2 \cdot (1-p) + 1^2 \cdot p = p. \end{align*}
So:
\begin{align*} \Var(X) \amp \E\left(X^2\right) - \left(\E(X)\right)^2 = p - p^2 = p(1 - p). \end{align*}
In Context