Question
A map of topological spaces $f: X \rightarrow Y$ is called locally constant if for every $x \in X$ there is an open neighbourhood $U_{x} \subset X$, x $\in U_{x}$, such that $f$ is constant on $U_{x}$. Prove that if $X$ is connected, then any locally constant map $f: X \rightarrow Y$ is constant, i.e. $f(X)$ is a point.
Proof.
Assume f is locally not globally constant. And let's restrict f to be surjective and it's image Y to have the discrete topology (this doesn't change the map itself). We can notice that f is continuous, since $$B = \{ \{y\} |y \in Y\}$$ is a basis for the topology of Y it's enough to show that $f^{-1}(\{y\})$ is open. But this is clear, since for any $x \in f^{-1}(\{y\})$ we have open $U_x \subset f^{-1}(\{y\})$. Thus f is continuous. Now let $$g: Y \rightarrow \{0,1\}$$ be a map, for which g(y') = 0 for some $y' \in Y$ and g(y) = 1 for $y \in Y$ and $y \neq y'$. Clearly map g is continuous (since all maps from discrete topological spaces are continuous). So $$g \circ f : X \rightarrow \{0,1\}$$ is a continuous, surjective map (surjective since we assumed f is not globally constant). This is a contradiction, since X is connected.
Doubts
Is this proof correct? I'm not sure I can change topologies just like that. The change doesn't affect the map and if a non-globally constant function f exists for any topology on y, then it also exists for the discrete one. I know there's a much simpler solution to this.