I believe the answer is adaptation through evolution. Genetic diversity in populations such as bacteria, allow for new traits to be passed along during reproduction. For example, you use hand sanitizer on your hands. The hand sanitizer kills most of the germs, but a few survive and live to reproduce, passing on their immunity to certain chemicals found in the hand sanitizer. Hope this helps!