Or, to put it another way...
If the sharps and flats are at the beginning of the line, that is the key signature. Whatever sharps or flats are there, those affect the entire staff, through all the measures of the piece, and if for example, the key signature is sharp on the F4 line, then all Fs are sharp, not just F4.
An accidental occurs throughout the score whenever a sharp or flat is needed that is NOT in the key signature, and affects ONLY the line it is found on, for ONLY the measure it is in.
Hope that clarifies things a bit.

Phil