I understand that when an ideal gas is compressed using a piston, the piston does work on the gas and increases the gas's kinetic energy (so temperature). However, I do not understand why a gas is cooled when the piston is lifted and the gas expands. Where does the kinetic energy of the go?
A real life example of this would be the gas coming out of a can of deodorant being cold.