Necessary and sufficient condition for the continuity of a function Let $E$ be a topological space and $A\subset E$ how to find a necessary and sufficient condition for the continuity of the function $\chi_A: E\rightarrow\mathbb{R}$ where 
$$
\chi_A(x)=
\begin{cases}
1, ~x\in A\\ 
0,~x\not\in A
\end{cases}
$$
If i suppose that $\chi_A$ is continuous  then $$\forall\varepsilon>0, \exists V\in \mathcal{V}_x, \chi_A(V)\subset ]\chi_{A}(x)-\varepsilon, \chi_A(x)+\varepsilon[$$ or 
 $$\forall\varepsilon>0, \chi_A^{-1}(]\chi_{A}(x)-\varepsilon, \chi_A(x)+\varepsilon[)\in \mathcal{V}_x $$
How to find a condition on $A$? 
Thank you
 A: The inverse image (by a continuous function) of a closed set is closed, so $A$ should be closed as the inverse image of a singleton $\{1\}$. Similarly, the complement of $A$ should be closed as an inverse image of $\{0\}$. Then $A$ should be a clopen set. If $A\in\{\emptyset,E\}$, the characteristic function is constant, so it is continuous. This is the only possibility in a connected space. Now let's consider a proper clopen set $A$ in a disconnected space. Could you continue with the check whether $\chi_A$ is continuous?
A: Necessary and sufficient condition for $\chi_A$ to be continuous is that $A$ is both open and closed.
Necessity. If $\chi_A$ is continuous, then $\chi_A^{-1}(-\infty,1/2)=X\setminus A$, $\chi_A^{-1}(1/2, \infty)=A$ are open.
Sufficiency. Assume that $A$ and $X\setminus A$ are both open, and $U\subset\mathbb R$ open. Then
$$
\chi_A^{-1}(U)=\left\{
\begin{array}{ccc}
X &\text{if}& 0,1\in U,\\
A&\text{if}& 1\in U \,\&\, 0\not\in U\\
X\setminus A&\text{if}& 0\in U \,\&\, 1\not\in U\\
\varnothing&\text{if}& 0,1\not\in U. 
\end{array}
\right.
$$ 
and hence 
$\chi_A$ is continuous.
A: Let's work locally. Take $x_0 \in E$. If $\chi_A$ is continuous at $x_0 \in E$, for every $\epsilon>0$ there is a neighbourhood $V$ of $x_0$ such that $x \in V$ implies $\chi_A(x) = \chi_A(x_0)$. So for all points in $A$ (for which $\chi_A(x_0)=1$, we find a neighbourhood of it which is contained in $A$, and so $A$ is open. Similarly for $A^c$ replacing $1$ by $0$ we find that $A$ is closed.
So $\chi_A$ continuous implies $A$ clopen. Conversely, if $A$ is clopen, take $(x_\alpha)$ a net converging to $x$. If $x \in A$, then $x_\alpha \in A$ for large $\alpha$ and so $\chi_A(x_\alpha) \to 1$. If $x \not\in A$, since $A^c$ is open, a similar argument shows that $\chi_A(x_\alpha)\to 0$. So $\chi_A$ is continuous.
