<s>[INST] Variance of binomial distribution Why for $X\sim B(n,p)$ is $Var(X)=np(1-p)$?
$Var(X)=\sum x_i^2 p_i -(\sum x_i p_i)^2=\sum_{r=0}^n r^2 \binom{n}{r}p^r(1-p)^{n-r}+( \sum_{r=0}^n r \binom{n}{r}p^r(1-p)^{n-r} )^2$
In my short-sightedness, I don't see any viable ways to derive the variance from this.
 [/INST] An easier way is to recognize that $X = Y_1 + Y_2 + \cdots Y_n$ where $Y_k$ are independent Bernoulli random variables with parameter $p$. For a Bernoulli random variable $Y_k$, we have $$\text{Var}(Y_k) = p(1-p)$$ Since $Y_k$ are independent, we have that 
$$\text{Var}(X) = \text{Var}(Y_1) + \text{Var}(Y_2) + \cdots + \text{Var}(Y_n) = np(1-p)$$
To go the direct way, we need to first evaluate couple of summations.
We will evaluate the sums $$\sum_{k = 0}^n k \mathbb{P}(X=k) \text{ and }\sum_{k = 0}^n k^2 \mathbb{P}(X=k)$$
First note that $\mathbb{P}(X=k) = \dbinom{n}k p^k (1-p)^{n-k}$. Hence, $$\sum_{k = 0}^n k \mathbb{P}(X=k) = \sum_{k = 0}^n k \dbinom{n}k p^k (1-p)^{n-k}$$
Note that $$k \dbinom{n}k = \dfrac{n!}{(n-k)! (k-1)!} = n \dbinom{n-1}{k-1}$$ Hence,
\begin{align}
\sum_{k = 0}^n k \mathbb{P}(X=k) & = \sum_{k = 1}^n n \dbinom{n-1}{k-1} p^k (1-p)^{n-k} = np \sum_{k = 1}^n \dbinom{n-1}{k-1} p^{k-1} (1-p)^{(n-1)-(k-1)}\\
& = np \left( p + (1-p)\right)^{n-1} = np
\end{align}
Similarly,
\begin{align}
k^2 \dbinom{n}k & = k \dfrac{n!}{(n-k)! (k-1)!} = n k \dbinom{n-1}{k-1}\\
& = n (k-1) \dbinom{n-1}{k-1} + n \dbinom{n-1}{k-1}\\
& = n(n-1) \dbinom{n-2}{k-2} + n \dbinom{n-1}{k-1}
\end{align}
Hence,
\begin{align}
\sum_{k = 0}^n k^2 \mathbb{P}(X=k) & = \sum_{k = 2}^n n(n-1) \dbinom{n-2}{k-2} p^k (1-p)^{n-k} + \sum_{k = 1}^n n \dbinom{n-1}{k-1} p^k (1-p)^{n-k}\\
& = n(n-1)p^2 + n p
\end{align}
Hence,
\begin{align}
\text{Var}(X) & = \sum_{k = 0}^n k^2 \mathbb{P}(X=k) - \left(\sum_{k = 0}^n k \mathbb{P}(X=k) \right)^2\\
& = n(n-1)p^2 + n p - (np)^2 = n^2p^2 - np^2 + np - n^2 p^2\\
& = np(1-p)
\end{align}
</s>