I'm focusing on the language of classic algebraic geometry.
Let $X$ be an affine variety and $A(X)$ be its coordinate ring. Let $E,F\subseteq X$ be $2$ disjoint closed subsets of $X$. Does there exist an $f\in A(X)$ such that $f(E) = 0$ and $f(F) = 1$?
If this is true, is there any generalization of this or in the language of scheme?
Yes, this is true. Let $R,S$ be the coordinate rings of $E,F$ respectively. Then $R\times S$ is the coordinate ring of $E\cup F$ as $E$ and $F$ are disjoint, and $A(X)\to R\times S$ is a surjection because $E\cup F$ is a closed subvariety/subscheme of $X$. So there is an element of $A(X)$ which has image $(0,1)\in R\times S$ and does exactly what you want. This proof works just fine for both affine schemes and affine varieties.