I'm trying to understand an example on finding Variance of a random variable. See example here on StatLect. Here's the relevant excerpt where I'm stuck.
Let $X$ be a discrete random variable with support
$$R_X = \{0,1\}$$
and Probability Mass Function (PMF)
$$p_X(x) = \begin{cases} q & \text{if $x=1$}, \\1-q & \text{if $x=0$}, \\0 & \text{$otherwise$} \end{cases}$$
where $0\le q \le1$.
I'm trying to figure out the alternative approach mentioned in the example where in order to find Variance I have to find the expected value $E[(X-E[X])^2]$.
I was able to figure out $E[X]$ easily. I computed the support $R_Z$ of $Z = (X-E[X])^2$ by evaluating Z for each value X and corresponding $E[X]$ would take. That gave me the support $R_Z = \{(1-q)^2, q^2\}$. Is this approach correct BTW?
It is this next step where the author computed PMF for Z which I could not figure out. He computed the following PMF
$$ p_Z(z) = \begin{cases} q & \text{if $z=(1-q)^2$}, \\1-q & \text{if $z=q^2$}, \\0 & \text{$otherwise$} \end{cases}$$
I guess this is trivial but how do I find what would be the probability of Z at $z=(1-q)^2$ and $q^2$?