An electric motor and an electric generator have almost identical structure and parts. Motor is used to convert electricity into mechanical energy. Generator is used to convert mechanical energy in to electricity.
Generator shaft is rotated by (potential energy of) water or steam energy (work done by pressure), then changing magnetic flux through the armature coil generates AC current, as long as the shaft rotates.
In Motor the shaft wound with current carrying coil is rotated by the magnetic force on the current carrying armature coil, due to change in magnetic flux.
Same principle and same parts in both. Motor and generator can function as both.