In text books, for instance in the 3rd edition of Introduction to Algorithms, Cormen, on page 625, the weights of the edge set $ E$ is defined with a weight function $ w:E\rightarrow \mathbb{R}$ .

Why is it defined in this way? Why do we need a function? I mean, we all know when working with a graph, that the meaning is just that an edge $ (u,v)$ as a weight $ w$ . So, why is it written with a function? I remember the first time I saw this definition I was very confused. Only after actually going through an algorithm and reading it again, I realized that it really just means that every edge has a its weight.

So, I still don’t fully understand why is it written in this complicated way and what exactly it means though, and it would be very nice if someone could tell me that in a understandable language.