My textbook says that a function is a set, and that it is a kind of relation, which is also a set.
Now: $$f(x) = x+5$$ is called a function, but the above expression is not a set. This is also true for other functions, like trigonometric functions such as $\sin x$, etc.
I have heard arguments that a function is a rule, and it is expressed as a set. But when we say a function is a kind of relation, this directly implies that it is a set.
So, what is a function?
The neat thing is that you can view it as both!
On one hand, a function can absolutely be thought of as a rule. If you are given a specific $x$ value, then a function like $f(x)=x+5$ tells you where $x$ gets mapped to. So a function can be interpreted as a rule which takes an input, transforms it, and then returns an output.
On the other hand, it can absolutely be thought of as a set. We can write this in set notation, something like $\{(x,x+5) \mid x \in \mathbb{R}\}$, but it’s actually even easier than that. You’ve already seen $f(x)$ as a set, in the form of a line on a graph! That line represents all the points in that same set of pairs written above.
As you go forward in mathematics, you’ll find this is often true, that objects can be viewed through multiple lenses, each of which offers its own insight :)