Firstly, don't be disheartened: one's first encounter with analysis is generally hard the way you're finding it. See for instance Herbert Wilf's piece Epsilon sandwiches, where he describes how this course is:
The one where students and epsilons meet, eyeball to eyeball, and it
isn't the epsilons that blink. The one where students decide that they
really wanted to be doctors and lawyers after all.
This course is famous for being our rite of passage. Our hazing
ceremony. If you want to join the club, then here is the hurdle that
you have to jump over.
And so on.
Secondly, the best way to understand a proof is to first try and prove the theorem yourself. Then when you read the proof, you'll have a better idea of what it's trying to do: you'll know which parts are just scaffolding, similar to what you'd have done yourself, and which parts are the new ideas, the real essence or new insight or trick that you should take away from the proof. This helps with all areas of mathematics β see Thurston's comment here:
"When listening to a lecture, I can't possibly attend to every word: so many words blank out my thoughts. My attention repeatedly dives inward to my own thoughts and my own mental models, asking 'what are they really saying?' or 'where is this going?'. I try to shortcut through my own understanding, then emerge to see if I'm still with the lecture. It's the only way for me, and it often works."
β but especially in analysis it's crucial because otherwise the $2\epsilon/3M$ and so on of slick proofs can appear to be pulled out of a hat.
Finally, to this particular question. You have a function $f$ that is $0$ at irrational points, and $\frac1q$ at rational points $\frac{p}q$. You want to prove that for any number $a$, the function approaches $0$ at $a$. Before reading the proof, you should try to prove it by yourself, so let's try.
We start with definitions: what does it mean to say that $f$ approaches $0$ at the point $a$? If you've internalized the definitions well, you should be able to say (and if not, this is a sign that you should go back and do that) what we want to prove: that $f(x)$ is sufficently close to $0$ for $x$ sufficiently close to $a$, or in formal words, for any $\epsilon > 0$, there exists $\delta$ such that if $|x-a| < \delta$β then $|f(x) - 0| < \epsilon$. And indeed, if you peek now at the proof, you'll see that it is of the form
To prove this, consider any number $\epsilon > 0$. [...]
if $0<|x-a|< \delta $, then [..] and therefore $|f(x)-0| < \epsilon$. This completes the proof.
so you've got the "skeleton" of the proof right.
Next, we worry about strategy: how are we going to prove that $|f(x) - 0| < \epsilon|$? We try to use what we know about $f$: that $f$ takes values either $0$ or of the form $\frac1q$. At points $x$ where $f(x) = 0$, we have $|f(x) - 0| = |0-0| = 0$, so it's certainly less than $\epsilon$ (as $\epsilon > 0$). So we only need to worry about $x$ where $f(x) = \frac1q$ for some $q$. In that case, $|f(x) - 0| = |\frac1q - 0| = \frac1q$. We'd like this to be less than $\epsilon$. (Now if we peek at the proof, we see that the second sentence is something about taking $n$ such that $\frac1n \le \epsilon$, so it's probably related to this, and we're on the right track.) Indeed, for any fixed $\epsilon$, as $q$ becomes larger $\frac1q$ becomes smaller and eventually becomes smaller than $\epsilon$.
So: to prove that $|f(x) - 0| < \epsilon$ for $x$ sufficiently near $a$, we do something akin to proof by contradiction: we look at when it's not true: $|f(x) - 0| \ge \epsilon$ when $f(x)$ is of the form $\frac1q$ for some $q$ such that $\frac1q \ge \epsilon$, and there are only finitely many such $q$. That is, if we take some fixed $n$ large enough so that $\frac1n \le \epsilon$, then the only $x$ for which $|f(x) - 0| < \epsilon|$ are those for which $f(x) = \frac1q$ for some $q \le n$, and $f(x) = \frac1q$ in turn means that $x = \frac{p}q$ for some such $q$, which gives the set of numbers in the proof.
So there are only these finitely many points $x$ at which the desired conclusion $|f(x) - 0| \le \epsilon$ might not hold. To avoid all of them, we must take $x$ very close to $a$ (note that to prove the desired conclusion, the only thing we can control about $x$ is its distance $\delta$ to $a$). That is, to make sure that $x$ is not any of these "bad points", we'll insist that $x$ must be closer toβ $a$ than any of these "bad points" are, i.e. we'll take $\delta$ smaller than the smallest of the distances of these "bad points" from $a$.
Then $x$ is surely not any of the "bad points" at which the desired conclusion $|f(x) - 0| \le \epsilon$ might not hold, which means that the conclusion holds. That's the rest of the proof, which I hope you'll be able to understand now.