Arduino code And library

Hello i would like to ask about how the Arduino executes the code that I wrote.
My understanding is that when I upload my code the library (which is a place where the different functions are described using a programming language. So when I write the code I need to write the function and I will find it's definition in the library ) is also uploaded into the microcontroller and then the microcontroller executes th code with the help of the library

Welcome to the forum

Any sketch that you write will have 2 functions that are part of it, setup() which runs once and loop() which runs over an over again

Those functions can contain straightforward code statements, calls to other functions in the sketch that you have written yourself or calls to functions in libraries

An example of the latter would be

 pinMode(9, INPUT_PULLUP);

The code for the pinMode() function would be copied from a library by the compiler and the code for it would be incorporated into the file that is uploaded to the Arduino

Common Arduino functions are in a library that you do not explicitly need to #include in your sketch but other functions, such as ones to read a specific type of sensor are in a library that you must #include in your sketch

In summary : the compiler puts the binary code needed to execute your sketch into a single file that is uploaded to the Arduino where it runs.

Once uploaded the Arduino does not need to be connected to the PC because its code is self contained

So It doesn't upload whole library with the code onto the Arduino. It only replaces the functions in the code like digitalWrite() with the code from the library. Before it's uploaded to the Arduino?

That is correct. Only the functions that you #include in your sketch become part of the code uploaded to the Arduino