When you first start learning to play a string instrument, the fingerings are often given to you. They are either printed in the music, or else your teacher tells you exactly what fingers you should use. Then, you learn that there are often multiple options for which finger and perhaps which string you could use for a given note, and the concept of fingering starts to get a lot more complicated. So how do you know which finger you should use?
Accidentals are sharps, flats, and naturals that may or may not differ from the key signature, depending on their purpose. You will see accidentals for any of the following reasons:
The composer wants you to play a note a half step higher or lower than what the key signature indicates.
A previous accidental is no longer in effect because you have crossed a bar line or a few bar lines since the last time you played a note with that staff position, so an accidental has been included just as a helpful reminder.
The key has just changed, and an accidental or perhaps a few accidentals might help in transitioning to a different hand frame.
On the violin and viola, we typically play flats or naturals with a low finger position and sharps with a high finger position. However, sometimes you need the finger you would normally use for the accidental in order to play the note that comes after it. That leaves you with three choices:
Slide your finger between the two positions.
Use an adjacent finger in a high or low position, instead.
Shift to a different position.
When sight reading, there isn't time to make a decision, and you have to go with the solution that occurs to you first. But when you are practicing, it's good to experiment with the options so that you can consider the balance between efficiency and sound. Maybe you don't want to slide your finger if you don't want to hear the slide, especially on a slur. Or perhaps shifting is a good idea, anyway, because of something coming up a few notes later.
You have to break free from any notion that a given note absolutely must be played with a given finger. As a beginner, thinking in finger numbers might be helpful, but it will ultimately hold you back. You need to have a good map of the fingerboard in your head and also be familiar with alternate routes so that you can comfortably take a detour in cases where whatever you would normally do won't work.