Proposition (continuous function on compact set attains its bounds)

Let $(X,\tau)$ be a topological space and $X\neq\emptyset$.

If $f: X\to\R$ is continuous and $(X,\tau)$ is compact, then $f$ is bounded and there exists $p,q\in X$ such that $$ \begin{align*} f(p) &= \sup_{x\in X} f(x) &\text{and}&& f(q) = \inf_{x\in X} f(x). \end{align*} $$

Proof