A generator is a machine that converts motion into electricity. There are generators in every power station. The rotary motion is generated there with a turbine.
Most bicycles are also equipped with a small generator. Here it is called a dynamo. It supplies the electricity for the lights. The power comes from the rider's muscles.
A car also has a generator. It is bigger than the one on a bicycle and is called an "alternator". However, it is not only responsible for the lights on and in the car, but it also feeds the battery. It also powers the electronics, the window lifters, the radio and everything else that needs electricity. The power comes from the petrol or diesel engine.
The fundamentals of the principle of action were discovered by the English natural scientist Michael Faraday in 1831, almost 200 years ago. The principle of action can also be reversed: If you feed electricity into a generator, it becomes a motor and turns electricity into movement.