A locomotive can derive power from many different sources. The earliest locomotives were driven by steam. Then came electric trains powered by galvanic cells. Later, onboard batteries were replaced by overhead lines. There are locomotives that run on internal combustion engines that drive the wheels of the locomotive directly using mechanical transmission like in automobiles, or use the rotational energy of the engines to generate electricity, which in turn run the traction motors.
Listen beautiful relax classics on our Youtube channel.