Q:

How is the expression of variance calculated

I saw this derivation of the variance formula $\text{Var}(X)=E[X^2]-(E[X])^2$ in the Wikipedia article on Variance:

I don't understand how to get from step 2 to step 3 (the section with the pink rectangle)

A:

Following principles applied:

Expected value of a sum is sum of expected values $E[Y+Z]=E[Y]+E[Z]$
Expected value is a constant $E[Y]\in\mathbb{R}$
Expected value of a constant is that constant $E[c]=c$
If you multiply a variable by a constant and calculate the expected value, it is the same as if you would calculate the expected value from the multiplied variable, i.e. $cE[Y]=E[cY]$
$$
E[X^2 - 2XE[X] + (E[X])^2]$$
Additivity
$$= E[X^2] - E[2XE[X]] + E[(E[X])^2]$$ 
Multiplication by constant
$$= E[X^2] - 2E[X]E[X] + E[(E[X])^2] 
$$
Expected value is a constant, expected value of a constant is the constant
$$= E[X^2] - 2E[X]E[X] + (E[X])^2 
$$

