Some can run on both. AC motors are the most generally used and that is all this is going to deal with. The changing of polarity in the magnets is caused by a change from positive to negative in the power supply. In the USA, thanks to the clock lobby, this happens 60 times per second. One cycle from zero through positive and negative and back to zero on one set of wires is called a phase.
Motors frequently are wound to run on one or more than one phase.
In the USA, single phase and three phase are the rule. Single phase motors require some mechanics to get around the starting problem. Three phase power has each phase reach zero 120 degrees out from each other. There is no way for the poles to line up exactly so it will always start. By definition, this is 550 foot pounds per second.