From the Super Mario Wiki
Trains, also referred to as N64 Expresses, are stage obstacles in Kalimari Desert in Mario Kart 64, Mario Kart 7, and Mario Kart Tour. They are red-and-black coal-powered steam locomotives with five passenger cars in Mario Kart 64, and three passenger cars in Mario Kart 7 and Mario Kart Tour. Both trains in the course travel along an elliptical track that the player crosses twice; at each crossing lies a crossbuck and a set of two lights that flash if a train approaches. The player flips over if they hit any part of the train, including the passenger cars. In Mario Kart Tour, the player performs a trick and is launched into the air if they touch a train.
In VS Mode for two players in Mario Kart 64, there is only one passenger car, while in the Grand Prix for two players, as well as in VS Mode for three and four players, all cars including the tender are removed. In the multiplayer mode for Mario Kart 7, one of the trains is absent.