Most modern passenger trains actually do both, using a configuration known as "push-pull" operation. In this setup, a locomotive is at one end of the train, and a special "cab car" (which looks like a regular passenger car but has a driver's seat and controls) is at the other. When traveling in one direction, the locomotive pulls the train; for the return journey, the engineer moves to the cab car at the other end and "remotely" drives the locomotive, which then pushes the train from behind. This system is highly efficient because it eliminates the need to uncouple the engine and turn it around at a terminus, allowing for much faster turnarounds. For heavy freight trains, locomotives usually stay at the front to "pull," though they sometimes use "distributed power" where additional engines are placed in the middle or at the rear of the train to provide extra "pushing" power for long, heavy loads over steep mountain grades.
Trains can both push and pull, depending on the configuration and operation:
In summary, trains can push or pull depending on the operational requirements and design of the rail system.