“How to spaceships fly in space when there is nothing to push against?”
Propulsion works following Newton’s 3rd Law: every reaction has an equal and opposite reaction.
Now with jet and propeller engines, they suck in the surrounding air and within the engine fuel is mixed and ignited with the fast moving air to produce thrust, which makes them move forward. But the downside is that there must be a significant concentration of air (and more importantly oxygen, since that combusts with fuel) in order to move at all. This is why airplane engines that work on Earth would not work on Mars (because the air density is too small) or Venus (because the air density is too much plus there’s little if no oxygen). Aircraft engines carry an efficiency factor of 60%-95%, depending on whether you are working with a Cessna propeller engine or a scramjet engine.
Automobile engines differ from jet engines in that they are not “air breathing” engines but rather the reactions occur internally within the engines. However, since the thrust created has to transition from the engine to the wheels via hydraulics, gears, etc, the efficiency factor is not that great.
Rockets, like auto engines, are not “air breathing” and create their thrust from internal reactions. BUT they use very efficient fuel which reacts 100% (meaning all of the fuel is used) and the thrust produced varies but is very powerful.Rockets are unique in that they employ the “De Laval” nozzles, which in general terms multiplies the force of the reaction by compressing the exhaust gases, choking it at the minimum area (called the throat): choking the flow causes the speed of the rocket to become supersonic easily.
This is why rockets work both as a launch vehicle and in space: they are completely independent of air. They can reach fast speeds that even scramjets are incapable of reaching (try Mach 25+) because scramjets are (fast) air-breathers. And efficiency is at 100% always.