How long does an engine last? It depends upon what class you're in, how modified it is, and how well you take care of it.
Most Late Model and Super Late Model engines around me are checked every week, and parts that are expected to wear (such as valve springs) might be replaced every two to three race nights. The whole engine might be rebuilt once per two months, although the high budget Super guys get them rebuilt almost every month. If the engine was abused (in a wreck, or overheated) then it is checked and either rebuilt or replaced. The low budget teams may stretch these time intervals out, but they know they are playing with hand grenades.
The crate engine classes tend to rebuild their engines about once per year, although they do replace pieces that are expected to wear probably at least once per month. Again, the bigger budget teams may rebuild more often. Unless a crate engine is abused it should last several seasons (with periodic refreshenings)... however the big budget guys usually replace an engine rather than rebuild it very many times. Low budget teams can get away with just replacing wear items and not refreshing for longer periods of time, but that puts them at a disadvantage since these classes are horsepower limited and you want as much horsepower as you can legally get. Note that most crate classes are "sealed motor" - meaning that except for a few outside adjustments only a certified engine shop is allowed to work on these engines.
In classes like Limited Modified or Street Stock where you're allowed to work on your own engine (albeit in a limited amount) an engine should last a few seasons. But they're more likely to be abused (wrecks, overheating, mistakes by inexperienced engine builders etc.) so they may not live that long. You also find a lot of used equipment in these classes (junkyard parts as well as used parts from higher classes) and you never really know how long used stuff will survive. We checked our motor every week, replaced wear items when we found them necessary, and refreshed "when the driver felt it might be down on power" (in other words, roughly once per year but it could vary... and he wasn't always right). Our engines were detuned versions of used Late Model engines and typically lasted three or four seasons - if the driver didn't wreck or if it didn't overheat.
In truly street car classes like Ucar the engine can outlast the car (due to wrecks), but most of these cars were already junky when they were converted from driving on the street to racing so you can't be sure. I've seen Ucars that raced for several seasons with no more than basic maintenance, and I've seen Ucar engines blow up during their first race night. Usually you're not allowed to do any modifications to these engines, so in theory they should last thousands of miles (which would translate into years of racing). However, those cars were not designed for racing and that abuse can kill them at any time - especially if they already saw lots of road miles first.
Kart engines also depend upon class. The "stock" classes usually run for several seasons, typically with one refresh per season. (I place "stock" in quotes because most of these motors are modified a little - usually parts swapped to make them safer and more reliable). But you'll find a lot of inexperienced engine builders in karts, and some of their engines meet their demise due to mistakes. You can race a "stock" engine for several seasons without working on it, but you will be at a disadvatage as it wears out. They also have classes for various levels of modified engines... generally these are hand granades that may last several seasons with very good care (and lots of refreshing) but more likely won't last more than about half a season. The karters are pushing their engines way beyond what they were designed to handle, so you don't expect them to last a long time.