Bear with me, I'm going to dive deep into how diesel trains do it, but first let me touch briefly on how subway cars, streetcars and the like do it. They use overhead wire or third rail to get typically 600-1500VDC. Heat and A/C runs directly on that. Lighting might run either on that directly, or on 240VAC made with an inverter, or on batteries. There's usually something in the lighting circuit to keep it from flickering. Batteries are typically 32 or 36 volts DC. Emergency lighting is batteries. In the old days, lighting was quite different, ask if you're curious.
OK. Here's how it's done on North American diesel-pulled passenger equipment.
One of the locomotives has an auxiliary generator onboard, which generates either 480 or 575 volts AC, three phase, 60 cycle. 480 is more common, and is commonly used in industrial shops all over North America. Some systems crank it to 575 volts so they can carry more power over the same thickness of cable (which is rated at 600V).
Locomotive generators are typically rated at 500kw or more - lots of power, enough to run a small town. Sometimes it's a shaft-driven alternator off the engine, but that forces the engine to run at one speed. Sometimes there's a semiconductor inverter that lets the engine run at any speed. Sometimes it's a second diesel engine.
Electricity comes back to the car via 480V connectors - typically four per car, though some systems go "cheap" and go with two or one. Here's a connector. It is the size of your forearm. http://www.nwrail.com/HEP_config.html
Each connector carries all three phases, plus a "sense" line. The heavy wires are 0000 gauge (also called 4/0 or "four-ought".) There are 4 connectors simply to allow more current to flow, and sometimes to allow two separate circuits. Poke around the site above and you'll find much more.
Now, about that sense line. 4-connector HEP typically has two connectors on each side of the car. Let's say A and B on the left, and C and D on the right. The sense wire is simply wired all the way through. At the rear end of the train, the end connector can't be exposed - it has 480VAC on those pins! So the "A" connector is simply plugged into the "B" connector. This is called "looping back" because it also means at the end of the rain, the sense wire loops from A to B. The locomotive sends a signal down the sense wire for "A", and it checks whether it gets the same signal back on "B". If it does, it knows everything's plugged in right and there are no exposed plugs. It does the same thing with "C" and "D". And if all that checks out, it knows it's safe to turn the power on.
Now, what do the cars do with the power? Heat runs directly on the 480VAC 3phase, big old heating coils like you find in an electric heater. The air conditioner is huge and also runs on the 480VAC 3phase.
The cars have 3 transformers, which reduce down to 240V single-phase with a center tap for 120V. This is exactly like the wiring in your house, except the transformers would be up on a telephone pole. All the little stuff runs on regular old 120V. The fluorescent lighting comes off the 240V circuits. Another power supply converts 240VAC to 28 volts DC to run those "airplane style" seat reading lights. 28 volts DC happens to be the voltage airplanes use.
Modern passenger coaches also have batteries, typically 32 volts or 36 volts. The batteries are charged from 240VAC. The batteries run auxiliary lighting, controls and a bunch of little stuff. There is a "load-shed" circuit on the battery that if the battery runs low, will shut down everything except critical safety systems - the intercom, the radio and the red rear marker light. I've been in the bathroom changing clothes when that happened.
What about high-voltage AC electrification like on the Amtrak northeast corridor? In that case, the cars work exactly as I described under "diesel", but the locomotive has the tricky job of converting high-voltage AC single-phase (which may be 60Hz or 25Hz) into 480VAC 60Hz 3-phase.