Locally Constant Functions on Connected Spaces are Constant I am trying to show that a function that is locally constant on a connected space is, in fact, constant. I have looked at this related question but my approach is a little different than the suggested approach and I'm unsure about the final step and would appreciate a tip. Here is what I have so far:
Let $f$ be a locally constant function on the connected space $U$. Assume that $f$ is not constant. Then, there are distinct points $x$ and $y$ such that $f(x) \neq f(y)$. Now, since $f$ is locally constant there are neighborhoods $V_x$ of $x$ and $V_y$ of $y$ such that
$$
f(V_x) = k_x, \;\; f(V_y) = k_y
$$
for some constants $k_x \neq k_y$ .It follows that $V_x \cap V_y =\emptyset$
Now, let $A = U-V_x \cup V_y$ and $B = V_x \cup V_y$ so that $U = A \cup B$. With this, we have expressed $U$ as a union of disjoint sets. Since $V_x$ and $V_y$ are open $B$ is open. Note that if $A$ is empty we are done because $V_x$ and $V_y$ would comprise a separation of $U$ wich would imply that the assumption about f being not constant was faulty. So, assume $A$ is nonempty.
At this point, I want to show that $A$ itself is open. If I can do this, I believe the proof will be complete. One way I've thought about doing this is to choose a neigborhood of some point $a \in A$ and if it is not already disjoint from $B$, shrink it until it is. This would then demonstrate that $A$ is open. 
Am I on the right track here?
 A: Are we don't need the hypothesis $f$ is continuous?
Since if we pick $z\in X$ then $A = \{x\in X: f(x) = f(z)\}$ is open, to see this, let $y\in A$, then by $f$ is locally constant, exist open set $B_y$ containing $y$ such that $f(B_y) =\{f(y)\} =\{f(z)\}$ so $B_y \subset A$. Otherwise, $X\backslash A = \{x\in X: f(x)\neq f(z)\}$ is also open, let $w\in X\backslash A$, then exist open set $B_w$ containing $w$ such that $f(B_w) = \{f(w)\}$, so $B_w \subset X\backslash A$.\
Hence $X = A\cup (X\backslash A)$ where $A$ and $X\backslash A$ are open, by connectedness we have $X = A$ since $A\neq \emptyset$
A: Let $\mathcal{S}$ be the set of open sets in the domain such that $f$ is constant on the open set.
Since $f$ is locally constant, we know that every $x\in \mathrm{dom}\, f$ is a member of some $S\in \mathcal{S}$.
Now, pick $x_0$, and define two sets: $U = \{x: f(x)=f(x_0)\}$ and $V=\{x: f(x)\neq f(x_0)\}$.
We can see that $U$ and $V$ are disjoint, and $U \cup V = \operatorname{dom} f$.
But each of $U$ and $V$ is just a union of open sets, namely sets in $\mathcal{S}$.
So $U$ and $V$ are both open.
A: For each point $x \in X$, pick an open neighbourhood $U_x$ such that $f$ is constant on $U_x$. Obviously, $X = \bigcup_{x\in X} U_x$ and $U_x \neq \emptyset$ for all $x$. Now, for $x \neq y$, two things can happen:


*

*$U_x \cap U_y \neq \emptyset$ and then $U_x = U_y$, or

*$U_x \cap U_y = \emptyset$.


If there exist two points for which the second is true, then $X$ would not be connected. So we are in the first case for all pairs of points in $X$ and there is just one $U_x$. Hence, $f$ is constant.
A: A variation and expansion of some of the ideas here:
In my first course on topology we were taught a following useful "chain-characterisation" of connectedness. Some definitions first: if $\mathcal{U}$ is a cover of a space $X$, then a chain in $\mathcal{U}$ is a finite indexed set $U_1,\ldots U_n \in \mathcal{U}$ such that for all $i=1,\ldots n-1$ we have that $U_i \cap U_{i+1} \neq \emptyset$, and it is called a chain from $x$ to $y$ in $\mathcal{U}$ (both points from $X$) when we additonally have $x \in U_1$ and $y \in U_n$.
Now:

A space $X$ is connected iff for every open cover $\mathcal{U}$ of $X$ we have a chain in $\mathcal{U}$ between any pair of points of $X$.

The chain-condition implies connectedness, because if $X$ is non-connected, we have decomposition of $X$ into 2 non-empty disjoint open sets $U$ and $V$, and then for $x \in U$ and $y \in V$ there can be no chain from $x$ to $y$ in the cover $\mathcal{U} = \{U, V\}$.
The reverse implication is a variant of the proofs in other replies: let $\mathcal{U}$ be any open cover of $X$ and fix $x \in X$. Then define $O$ to be the set of all $y \in X$ such that there is a chain from $x$ to $y$ from $\mathcal{U}$.
$O$ is non-empty, as any $x$ in $X$ is covered by some $U \in \mathcal{U}$ and then $U_1 = U$ is a chain from $x$ to $x$, so $x$ is in $O$.
$O$ is open: let $y$ be in $O$ and let $x \in U_1,\ldots U_n$ be a witnessing chain (from $\mathcal{U}$) for it. Then for every $z$ in $U_n$, that same chain will witness that $z$ is in $O$ as well, and so $U_n \subset O$, and every point of $O$ is an interior point.
Note that we do not even need the cover to be open, just that the interiors cover $X$.
$O$ is closed: suppose that $y$ is not in $O$, and let $U$ be an element from $\mathcal{U}$ that covers $y$. Suppose that some $z$ in $U$ is in $O$, and again let $x \in U_1,\ldots U_n$ be a witnessing chain for it, so with $z \in U_n$. But then the chain $x \in U_1,\ldots U_n,U_{n+1} = U$ is a chain from $\mathcal{U}$ as well, because all intersections are non-empty in the beginning by assumption, and $U_n \cap U_{n+1}$ is non-empty, as both contain $z$, and this would witness that we have a chain from $\mathcal{U}$ from $x$ to $y$. But then $y$ would be in $O$, contrary to what we assumed. So $U$ misses $O$ entirely so $O$ is closed.
But now the connectedness of $X$ forces $O = X$ (there is only one non-empty clopen set) and then we have what we wanted in the chain condition, as $x$ was arbitrary.
Having this at our disposal we are almost done: let $f$ be locally constant and for every $x$ pick a neighbourhood $U_x$ such that $f$ is constant on $U_x$.
We of course consider the cover $\mathcal{U} = \{U_x : x \in X \}$, and fix $x$ in $X$.
If $y$ is another point in $X$ then we have a chain from $\mathcal{U}$ from $x$ to $y$ but when 2 sets from $\mathcal{U}$ intersect, it means $f$ is constant on their union. It follows that $f(x) = f(y)$ as required.
Other applications: in a locally compact (in the sense of every point has a compact neighbourhood) connected space for every $2$ points there is a compact subset of $X$ that contains them both. Or a locally path-connected and connected space is path-connected
(use path-connected open neighbourhoods, get a chain from $x$ to $y$, a glue together paths from $x$ to a point in the intersection of $U_1 \cap U_2$, a point in $U_2 \cap U_3$ etc to $y$.) and so on. It allows for all sort of local properties to get expanded more globally for connected spaces.
A: The fastest proof is probably the one already mentioned: pick $x$ and show that $f^{-1}(f(x))$ is clopen. Another way, which looks like Agustí's approach, is the following.
Let $f:X\to Y$ be locally constant. Define the following relation on $X$:
$x\sim y:\Leftrightarrow (f\text{ is constant on some open }U\supseteq\{x,y\}).$
It is reflexive because $f$ is locally constant. It is trivially symmetric. It is transitive because if $f$ is constant on $U$ and $V$ with $U\cap V\neq\emptyset$ then $f$ is constant on $U\cup V$.
Thus $\sim$ is an equivalence relation, and we get a partition $P=\{[x_i]\ |\ i\in I\}$ of X. There is a nice description of the equivalence classes, namely
$[x]=\bigcup \{U\text{ open }\ |\ x\in U,|f(U)|=1\}$
i.e. it is the biggest open set containing $x$ on which $f$ is constant. Thus
$X=\bigcup_{i\in I}[x_i]$
is the disjoint union of non-empty opens. If $X$ is connected, then we must have $|I|=1$, i.e. $f$ is constant on $X$.
A: I think there another argument that hasn't been mentioned here yet. Let $f:X\to S$ be a function from a topological space $X$ to a set $S$. Then $f$ is continuous when $S$ is endowed with the discrete topology if and only if for all $x\in X$ there is a neighborhood $U\subset X$ of $x$ such that $f|_U$ is constant. On this case, we say that $f$ is locally constant. In particular, if $X$ is also connected, then $f(X)$ is connected since continuity preserves connectedness. Since $S$ is totally disconnected (as discrete spaces are), $f(X)$ is a point.
