In an economic climate in which 40% of Americans say they would struggle to come up with $400 for an unexpected expense — according to a report from the Federal Reserve — it’s tough to mine humor within hardship. But that hasn’t stopped television producers and network execs from trying.

A number of today’s comedies, from ABC’s “The Conners,” to Showtime’s “Shameless” and NBC’s “Superstore,” center on the working class. Meanwhile the upcoming “Broke” (CBS) and “Indebted” (NBC) focus on those who once had money but lost it and are now humbly learning how the other side has been living. The key for these series’ writers and producers, though, is to infuse a complicated reality with dialogue and scenarios that can make a tough socioeconomic situation more palatable — without pandering or being used as too much of a punchline.

“Everyone, no matter their circumstances, looks for the humor in life — gallows humor, self-deprecating humor — we all look to laugh, even or especially in the face of difficult times,” says “Shameless” executive producer John Wells.

This is not a completely new trend, as classic sitcoms from “The Honeymooners” to “Good Times” and “Roseanne” (of which “The Conners” is an updated spinoff) relied on blue-collar comedy to provide a level of down-to-earth levity people trust and respect, notes David Rae, a financial planner and wealth manager.

“When Americans tune into shows like ‘The Conners’ and ‘Shameless,’ they see people dealing with issues that they are facing,” Rae says. “There is still plenty of room for escapist shows like ‘Game of Thrones,’ but sometimes you just want to sit back and watch someone like you drink a beer and complain about their crappy job, or face some dire financial choice.”

Of course, every show walks its own line of how much the characters’ fickle finances inform plot, setting or, perhaps more simply, motivation and backstory. “Shameless” deconstructs the actions of a lower-middle-class, mostly white family in Chicago and all the ways each of the brood cunningly tries to make ends meet.

“Why would we not want to tell the stories of nearly half of the population?” asks Wells.

Meanwhile, “Superstore” is a workplace comedy about diverse employees at a big-box store further exploring the disparity between the haves and have-nots, even among that already middle class group. In the fourth season, Marcus (Jon Barinholtz) secretly moved into the store, and workers considered unionizing after their reduced hours hit their pocketbooks.

“These themes have been part of our show from the beginning,” says co-showrunner Gabe Miller. “Unfortunately, these days it’s impossible to write a show about employees at a big-box store without dealing with economic hardship. And with the way automation and the internet have changed the world of retail, the idea of unionizing felt like something that our characters would be considering more and more urgently.”

Making unions and even semi-homelessness funny also created its own set of challenges, says Jonathan Green, who co-showruns “Superstore” alongside Miller: “We’d been discussing for a few seasons the idea of someone having to secretly live in the store. Doing it as a subplot with Marcus, coming from his terrible money management, allowed us to keep it funny, instead of saying, ‘This is our homelessness episode.’”

“Superstore” relies on real-life research, such as talking to organizing groups about labor issues and touring big-box stores to ensure, even in the more comical moments, the stories are rooted in truth. But the fact that the show conveys these issues through comedy is what Ben Feldman, who plays Jonah, feels captures audience attention.

“We all know people going through real-life hardships of one level or another and I often find that even those who are deep in it still manage to maintain a sense of humor or find time to turn their attention towards the ordinary and ridiculous minutiae of everyday life,” he says.

“It’s how we survive everything from personal tragedy to Trump. And it’s that ability to be blissfully myopic that allows a show like ours to find laughs among characters that might be dealing with very dark issues when you zoom out.”

But even programs that are not strictly about the working class have delved into tales of economic shortcomings and the sometimes-humorous and sometimes-bleak scenarios they can cause. For instance, on HBO’s “Insecure,” heroine Issa Dee (Issa Rae) had to couch-surf at her ex-boyfriend’s place when she could no longer afford her rent in the third season. “Atlanta” on FX had Earn (Donald Glover) living in a storage locker at one point. Then there’s “The Bold Type,” a Freeform drama that follows three fashion-forward friends as they navigate the cutthroat world of glossy sartorial magazines in New York.

While that series is mostly aspirational — who wouldn’t want to borrow high-end clothes and accessories from the publication’s closet full of designer labels? — Sutton (Meghann Fahy) grew up poor, and often wrestles with her humble beginnings as she strives for both personal and professional success. For her third season storyline, Fahy says one of the writers who grew up in trailer park helped flesh out Sutton’s realistic monetary fears.

“There wasn’t much room for error for Sutton, which is why taking risks in her career feels extra scary for her,” Fahy says.

“The stakes are perhaps a bit higher. If she can’t make it work in NYC she’d likely have to move back home, because she doesn’t have a family who can help support her in that way.”

For Fahy, the most important part of telling Sutton’s story is to provide perspective and show off the heart and humanity in what can often be seen as a less-than-desirable story topic. “To have an awareness of another person’s privilege or lack thereof and how that affects a person’s life is valuable,” she says. “Through opening our ears and hearts to others we can foster our empathy and tolerance in ways that can change the way we see the world and ourselves.”