This is the definition of random variables I found out:
A random variable is a function that assigns values to each of an experiment's outcomes.
For example, if we toss two different coins at a time and let random variable $X$ be the numbers that the coins come up heads, then we have $X : \{HH, HT, TH, TT\} \rightarrow \{0,1,2\}$ where, for example, $X(HH) = 2.$
However, a problem occurs when I think about continuous random variables. For example, if I let $X$ be height of students. I understand that random variable $X$ is continuous since its value can be any real numbers in, let's say, an interval $[140, 200].$ However, what is the domain of this random variable $X$? If the domain is the set of students, then the range can be listed.

In the continuous case you mention we can choose $X$ to be the function $[140,200]\to\mathbb R$ that is prescribed by $\omega\mapsto\omega$.
That is not a "must" however. We are dealing with a real world situation that must be modeled by means of a probability space and there are lots of ways to do that.
The one I just prescribed is the most natural one (i.e. the first thing that comes up in my mind).
A list of students will not do here as outcome space, because then automatically $X$ is a function that can only take a finite number of values.