Believe it or not, electricity and magnetism are very closely related. Anytime you have electricity flowing through a conductor, a magnetic field is created around it. Anytime you move a magnet near a conductor, you create electron flow inside of it, which can be considered electricity. In fact, this is how your alternator works.
I don't want to get too deep into this, but it is a concept that needs to be covered. As I said, an alternator works because it houses a series of electromagnets that are moved near a conductor, thus causing electricity to be generated. The mechanical movement of the engine is used to drive the alternator, which in turn converts the mechanical energy of the engine into electrical energy inside the alternator. Conversely, we create magnetic fields inside the starter motor to produce mechanical energy from electrical energy so we can start the engine. It just depends on how it’s used. Just know that electricity and magnetism go together like chocolate and peanut butter.
This principal is used throughout automotive electrical systems to do mechanical work or to generate the electricity that runs the vehicle. In fact, this is how many hybrids work. They use a starter/alternator assembly on the back of the engine in place of a flywheel. This device makes it possible to use the flywheel as the starter and alternator for the engine. It generates electricity and works as an alternator as long as the engine is running. It also makes it possible to shut the engine off when you’re sitting at a stop light. When you accelerate, this device transforms into a starter and gets the engine going again. It can generate electricity as the engine is running and the vehicle is driving just like an alternator would. It all depends on how the magnetic fields are being used at the time. It's pretty cool stuff that I hope to make some videos about at some point. For now, we'll cover electricity and magnetism in general terms and move on.