In this question:
universal property in quotient topology
I saw the following theorem:
Let $X$ be a topological space and $\sim$ an equivalence relation on $X$. Let $\pi: X\to X/{\sim}$ be the canonical projection. If $g : X → Z$ is a continuous map such that $a \sim b$ implies $g(a) = g(b)$ for all $a$ and $b$ in $X$, then there exists a unique continuous map $f : X/{\sim} → Z$ such that $g = f ∘ \pi$.
I was wondering how one would prove this.
For $x\in X$ let $[x]$ denote that $\sim$-equivalence class of $x$; $X/{\sim}=\{[x]:x\in X\}$. To show that such an $f$ exists, we simply define it: for $[x]\in X/{\sim}$ let $f([x])=g(x)$. Now use the fact that $g$ is constant on $[x]$ to show that $f$ is well-defined.
To show that $f$ is unique, suppose that $h:X/{\sim}\to Z$ is continuous and satisfies $g=h\circ\pi$. Let $[x]\in X/{\sim}$ be arbitrary. Then
$$f([x])=(f\circ\pi)(x)=g(x)=(h\circ\pi)(x)=h([x])\;,$$
and hence $f=h$.
To show that $f$ is continuous, let $U$ be an open set in $Z$. Show that $$f^{-1}[U]=\{[x]\in X/{\sim}:x\in g^{-1}[U]\}\;,$$ and then use the fact that $X/{\sim}$ bears the quotient topology to conclude that $f^{-1}[U]$ is open in $X/{\sim}$.