Former president Barack Obama at an early-November campaign rally in Gary, Ind. (Luke Sharrett/Bloomberg News)

Former president Barack Obama on Tuesday pushed back against the notion that Democrats need to elect a candidate of a certain race or gender to beat President Trump in 2020, as some in the party have argued.

Obama weighed in on the choice Democrats face in a wide-ranging podcast interview with his former top strategist David Axelrod at the University of Chicago Institute of Politics. Axelrod is a CNN commentator and the institute’s director.

Asked about those who say the party would make a mistake in selecting another woman or candidate of color as its presidential nominee, Obama responded, “That kind of stuff, I don’t buy.”

“With respect to going forward, the idea that there’s some demographic or profile of a particular candidate that is the optimal one or the ideal one, that’s just not how I’ve seen politics work,” Obama said. “I think people respond to candidates who speak to the moment in some fashion.”

Neither Obama nor Axelrod mentioned any names, but several potential White House contenders have recently weighed in with their thoughts on the ideal profile for a Democratic candidate — in one case, even before the 2018 midterm elections had concluded.

Attorney Michael Avenatti said in an interview with Time magazine last month that he believes a white man would have the best chance at winning.

“I think it better be a white male,” said Avenatti, who is openly mulling a White House bid. “When you have a white male making the arguments, they carry more weight. . . . Should they carry more weight? Absolutely not. But do they? Yes.”

Critics swiftly denounced the comments as perpetuating racist and sexist stereotypes. Avenatti defended himself in a tweet in which he said he has “consistently called on white males like me to step, take responsibility, and be a part of stopping the sexism and bigotry that other white males engage in.”

Another potential contender, Sen. Bernie Sanders (I-Vt.), also came under fire after an interview this month with the Daily Beast in which he said that there are “a lot of white folks out there” in Florida and Georgia “who are not necessarily racist who felt uncomfortable for the first time in their lives about whether or not they wanted to vote for an African American.”

“I think next time around, by the way, it will be a lot easier for them to do that,” Sanders said.

Tallahassee Mayor Andrew Gillum (D) in Florida and former state House minority leader Stacey Abrams (D) in Georgia narrowly lost their gubernatorial bids this month. If elected, Gillum and Abrams would have become the first black governors of their respective states. A Sanders spokesman later clarified in a statement to NPR that the senator was speaking about racist attacks made against both candidates.

Andra Gillespie, a political-science professor at Emory University, recently told The Washington Post that Abrams’s strong showing in Georgia should silence the faction of Democrats and progressives who were “worried about whites not voting for a black candidate.”

The debate over the 2020 field is playing out against the backdrop of a newly elected Congress in which women and nonwhite lawmakers will constitute a majority of the House Democratic caucus.

In Tuesday’s “Axe Files” interview with Axelrod, Obama cited his 2008 victory as well as Trump’s in 2016 as examples of how generalizations about the chances of certain candidates proved wrong.

“You don’t know how all these various factors are going to converge until you try,” he said.

He did, however, contrast his view of the nation with what he described as that of the current president.

“I think what’s unique about America is our aspirations to be a large, successful, multiracial, multicultural, multiethnic, multi-religious, pluralistic democracy,” Obama said.

“Do you think that’s President Trump’s vision?” Axelrod asked.

Obama responded without hesi­ta­tion.

“No. Obviously not,” he said. “We have contrasting visions about what America is. And that’s self-apparent.”