Why do snakes seek out environments that provide both sunny spots and cool, dark places?

Answer

To regulate their cold-blooded body temperature.

Being cold-blooded, snakes require sunny spots for basking when they need to raise their temperature and cool, dark places for retreat when it becomes too hot.

Why do snakes seek out environments that provide both sunny spots and cool, dark places?
venomavoidanceSafetyreptilesnake