Proposition (locally constant function on connected domain is globally constant)
Let $(X,τ)$ be a topological space, $Y$ be a set, and $f: X\to Y$ be a function.
If $X$ is connected and $f$ is locally constant (i.e. for all $x\in X$, there exists an open neighbourhood $U\subseteq X$ of $x$ such that $f(y) = f(x)$ for all $y\in U$), then $f$ is (globally) constant.
-
A consequence is that $X$ is connected iff all continuous functions $f: X\to\Z$ are constant.