In rail transport, a locomotive is the part of a train that makes the train move. Normally, it is the first part of the train, and has an engine. Some trains do not have a separate locomotive; they have motors in the other parts of the train.
A diesel locomotive is powered by a diesel engine. The diesel engine may drive the locomotive's wheels directly via a gearbox, shaft or chain (called mechanical transmission) or by using a hydraulic transmission system (diesel-hydraulic). Most of the locomotives in the world are diesel-electric, due to their ease of use and reliability. They generate electricity and use it to power the wheels. They can be more powerful than steam locomotives and do not need an expensive power grid like electric locomotives.
A steam locomotive uses wood, coal or oil (but mostly coal) as fuel to heat water in a boiler, which turns into steam which pushes pistons to power the train. Steam locomotives were invented in the early 19th century. They are not widely used any more due to their operational costs, especially the fuel costs; steam locomotives are now mostly only used on tourist railroads.
An electric locomotive runs on electricity as the name suggests. Electric locomotives cost the least to buy and operate. However, the railway electrification system is very expensive, so only tracks used by many trains per day are usually electrified. Thus, electrics are only the second next used type, behind diesel locomotives.