Let X and Y be a topological spaces.

Suppose X is the union of two closed subsets A and B of X .

Let f: A -> Y and g: B-> Y be continuous.

If f(x)=g(x) for every x in the intersection of A and B, then let h: X -> Y be a function defined by setting h(x)=f(x) for x in A, and h(x)=g(x) for x in B.

Then could we say that h is continuous ? Why?

This is called the gluing lemma. It applies to finitely many closed sets and arbitrarily many open.

So, suppose that \(\displaystyle X=A\cup B\) where \(\displaystyle A,B\) are closed subspaces of \(\displaystyle X\) and \(\displaystyle f:A\to Y\) and \(\displaystyle g:B\to Y\) are continuous functions such that \(\displaystyle f\mid_{A\cap B}=g\mid_{A\cap B}\) then \(\displaystyle f\sqcup g:X\to Y:x\mapsto\begin{cases}f(x)\quad\text{if}\quad x\in A\\g(x)\quad\text{if}\quad x\in B\end{cases}\) is well-defined since \(\displaystyle f,g\) agree on the intersection of their domains. Also, it's continuous since if \(\displaystyle E\subseteq Y\) is closed it is easy to see that \(\displaystyle \left(f\sqcup g\right)^{-1}(E)=f^{-1}(E)\cup g^{-1}(E)\). But, since \(\displaystyle f,g\) are continuous \(\displaystyle f^{-1}(E),g^{-1}(E)\) are closed subspaces of \(\displaystyle A,B\) respectively but since they themselves are closed subspaces of \(\displaystyle X\) it follows that so are \(\displaystyle f^{-1}(E),g^{-1}(E)\). Thus, \(\displaystyle \left(f\sqcup g\right)^{-1}(E)\) is the finite union of closed sets and thus closed. The conclusion follows.

This can be generalized, as I said, to a finite partition of closed sets or an arbitary partition of open ones.