Genetic variation enables bacteria to adapt to changes in their environment. Since, bacteria reproduce asexually (binary fission), they can share genes (genetic transfer) via other mechanisms such as conjugation (exchange of genetic material through direct contact between two bacteria), transformation, and transduction(exchange of genetic material via bacteriophages).
Transformation is a process by which bacteria takes in DNA from its environment through the cell membrane.