Libraries?

I was wondering why libraries existed? If it is all code why do we not put it in a sketch? Are they there to just simplify life or are there certain commands that can't go in an Arduino sketch?

It's to make coding simpler.
Libraries are kind of like a magic black box/recipe book.

With a library you have some bits exposed but "how" things are done is hidden inside the library. It's so you don't have to reinvent the wheel. Or make up your own recipe,.

They mainly exist so you don't have to constantly rewrite code fragments for all your sketches, and it does make things a hell of a lot easier and more appealing to the eye.

Okay. Thanks for the information.

You could put the code in the library, or a version of it, in your program but it would make the code unwieldy and messy to read and you would need to find it and copy/paste it in each time that it was required. The same goes for the Arduino functions such as pinMode, Serial.print etc. Think what a bind it would be to have to put the code for those in every program.

To elaborate more on what UKHeliBob said:
pinMode(), Serial.print() and just about anything else that you use regularly with ()'s is defined somewhere IN a library.
When you call pinMode(), you're sending it two parameters which is then manipulated by a (often) complex set of basic or binary commands so you don't have to.
You can write your own libraries if you want, and I've found it enjoyable (but yet oh so boring at the same time) to read libraries that come with the Arduino programming environment and those that I've downloaded for other devices that work with Arduino, such as a real time clock chip, LCD shield and a few others. It helps me understand a little bit more whats going on.

Make more sense now?