The key signature is a set of sharps or flats that is placed on the stave at the beginning of the song and at the start of a section if there is a key change. Every single note in the octave has two key signatures, major and minor.
To help you know key signatures, you can memorise the order of sharps and flats. The order of sharps are F, C, G, D, A ,E ,B and the order of flats are backwards, B, E, A, D, G, C, F. To help memorise this, I use a mnemonic which is Father Charles Goes Down And Ends Battle (order of sharps) and then Battle Ends And Down Goes Charles Father (order of flats).
Key signatures can be tough as you have to memorise what the key signature is because it is only shown at the start of each line.
On the left, there are all the key signatures. You will see that for every major key, there is a relative minor key. To easily find the relative minor, you count down three semitones from the major key, and you do the same but in reverse to find the major.
Here is a flute part for Bohemian Rhapsody by Freddie Mercury. It starts in Bb Major because it has two flats in the key signature at bar 1. This also could be in G minor because G minor also has 2 flats as it is the relative minor, but if you listen to it, it is in a major key and sounds brighter. But in the third line, it changes to C minor, with three flats. This could also be Eb major, but as it is in a minor key it is in C minor.
In the first 8 bars, every B and E are flattened. This is because of the key signature. Once it changes to C minor, there is the additon of A flat which means every B, E or A is flattened unless there is a natural sign.
Key signatures are very useful because without them you wouldn't know what key you are playing in, and it would sound all wrong. It would be hard to improvise as you don't know what key you would be in, this would be hard for jazz or blues musicians. With key signatures, there wouldn't be lots of accidentals on the page, which makes it look more clean and easy to read. However, you need to remember to look at the key signature at the start of the line in case it has changed.