Heat is a type of energy.
It can be transferred between two objects with two different temperatures. Heat
transfer always moves from the hotter object to the colder object, as a result,
the temperature of the hotter object decreases and the temperature of the cooler
object increases.
There are three methods of heat transfer: conduction, convection and radiation.
Here is a video showing the process of expansion and contraction by heat
Conduction transfers heat through direct contact between objects. Conduction transfer heat very well in solids.

Another type of heat transfer is convection. Convection transfers heat by the movement of a medium, like air or liquid. Convection transfer heat well through gases and liquids.

Radiation transfers energy by electromagnetic waves. This heat transfer method does not require any solid, liquid or gases. It can travel without any matter.

Video from YouTube on expansion and contraction process