Example of metric space that has more than two sets that are both closed and open? I'm curious if there are examples of metric spaces having more than two sets that are both closed and open.
Note: This is not for homework.  This is to help me better understand the concepts of computational topology, so that I may make my own proofs as well.
So I am thinking that this could involve sets that are partially closed, partially open.  Ie. a half ball with which one side is open (the boundary) and the other side is closed.
 A: You already know several such subspaces of $\Bbb R$ with the usual metric.


*

*$\Bbb Z$: Clearly $\left(n-\frac12,n+\frac12\right)\cap\Bbb Z=\{n\}$ for any $n\in\Bbb Z$, so $\{n\}$ is an open subset of $\Bbb Z$ for each $n\in\Bbb Z$. Since $A=\bigcup_{n\in A}\{n\}$ for any $A\subseteq\Bbb Z$, each subset of $\Bbb Z$ is open in the relative topology of $\Bbb Z$. This immediately implies that each $A\subseteq\Bbb Z$ is closed in $\Bbb Z$: if $U=\Bbb Z\setminus A$, then $U$ is open, and therefore $A=\Bbb Z\setminus U$ is closed. That is, every subset of $\Bbb Z$ is clopen (open and closed) in the $\Bbb Z$ with the usual metric.

*$\Bbb Q$: Let $q\in\Bbb Q$, and let $\alpha$ be any positive irrational; then $B(q,\alpha)=\{p\in\Bbb Q:|p-q|<\alpha\}$ is a clopen subset of $\Bbb Q$ with the usual metric. $B(q,\alpha)$ is certainly open in $\Bbb Q$. To see that it’s also closed, we’ll show that $\Bbb Q\setminus B(q,\alpha)$ is open. Suppose that $p\in\Bbb Q\setminus B(q,\alpha)$; then $p\ge q+\alpha$ or $p\le q-\alpha$. Suppose that $p\ge q+\alpha$. Since $p$ is rational, $p\ne q+\alpha$, and therefore $p>q+\alpha$. Let $\beta=(q+\alpha)-p>0$; then $$q-\alpha<q<q+\alpha=p-\beta<p<p+\beta\;,$$ so $B(p,\beta)\cap B(q,\alpha)=\varnothing$, where $B(p,\beta)=\{r\in\Bbb Q:|r-p|<\beta\}$. In other words, $B(p,\beta)$ is an open ball about $p$ such that $B(p,\beta)\subseteq\Bbb Q\setminus B(q,\alpha)$. If $p\le q-\alpha$, take $\beta=(q-\alpha)-p$ and argue similarly to show that $B(p,\beta)\subseteq\Bbb Q\setminus B(q,\alpha)$, and conclude that $\Bbb Q\setminus B(q,\alpha)$ is open and hence that $B(q,\alpha)$ is closed and therefore clopen. The open balls with irrational radius are not the only clopen subsets of $\Bbb Q$, but they’re easy to describe, and they clearly show that $\Bbb Q$ with the usual metric has infinitely many clopen subsets.

*$\Bbb R\setminus\Bbb Q$: If $x$ is irrational and $r>0$ is irrational, then $B(x,r)=\{y\in\Bbb R\setminus\Bbb Q:|y-x|<r\}$ is clopen in $\Bbb R\setminus\Bbb Q$ with the usual metric; the proof is very similar to the previous one.

*The middle-thirds Cantor set $C$: If $\alpha,\beta\in\Bbb R\setminus C$, and $\alpha<\beta$, then $U=(\alpha,\beta)\cap C$ is a clopen subset of $C$ with the usual Euclidean metric. Clearly $U$ is open in $C$, since it’s the intersection with $C$ of an open set in $\Bbb R$. On the other hand, $\alpha,\beta\notin C$, so $U=[\alpha,\beta]\cap C$; $[\alpha,\beta]$ is a closed set in $\Bbb R$, so its intersection with $C$ is a closed set in $C$, and $U$ is therefore closed as well as open.
A: Metric spaces that aren't connected can give such examples. For example, $(0, 1) \cup (2, 3)$ is a metric space (equipped with the usual Euclidean metric) and both $(0, 1)$ and $(2, 3)$ are open and closed in the topology induced by the metric.
Of course, as usual $\emptyset$ and the entire space are two more examples, for a total of four.
A: Let $X$ be any set.  For any two elements $x, y\in X$ let $d(x, y)=\begin{cases} 1 & \text{if } x\neq y\\ 0 & \text{if }x=y\end{cases}$.
This is called the discrete metric. In the metric space $(X, d)$, $\textit{every}$ set is both open and closed.
A: The situation is rather ubiquitous. If a metric space $(X,d)$ is locally of cardinality $<2^{\aleph_0}$ at a point $x\in X$, then $x$ has a nbhd basis consisting of clopen sets: if $B_d(x,r^*)$ is of cardinality $<2^{\aleph_0}$ then $D=\{r\in (0,r^*):\,S_d(x,r)=\emptyset\}$ is dense in $(0,r^*)$ (since all non empty interval in ℝ are of cardinality $2^{\aleph_0}$) and $\{B_d(x,r):\,r\in D\}$ is a clopen nbhd base of $x$. Note that $B_d(x,r^*)$ as above can be a very big set if the continuum is very big (e.g. if it is weakly hyper Mahlo, real valued measurable, etc.).
