Updated

Barack Obama has written before about his past drug use, but on Tuesday he took the rare and surprising step of talking about it in front of a group of high school students, telling them that he was a slacker when he was their age, more interested in basketball and girls than applying himself in school.

Obama addressed the issue after the principal at Central High School in Manchester, N.H., asked the Democratic presidential candidate to give the students a sense of his "human side," and what his life was like when he was in school. Obama was in Manchester to pitch his $18 billion education plan.

In response to the principal's question, the Illinois senator said: "I will confess to you that I was kind of a goof-off in high school ... I made some bad decisions that I've written about. There were times when I got into drinking and experimented with drugs ... There was a whole stretch of time when I didn't really apply myself a lot."

Obama said that his childhood in Hawaii was largely spent playing basketball and thinking about girls, and that it wasn't until he went to college that he realized he'd "wasted a lot of time."

"By the time I was a junior or senior in college, I got really serious. In fact, I was so serious that my mother told me to lighten up, because I'd become a complete grind — fortunately over time I got a little balanced," Obama said.

GOP candidate Mitt Romney, who was campaigning in Iowa Tuesday, called Obama comments a "huge error."

“It’s just not a good idea for people running for president of the United States, who potentially could be the role model for a lot of people, to talk about their personal failings while they were kids, because it opens the doorway to other kids thinking, ‘Well I can do that too,’” Romney said.

But Republican frontrunner Rudy Giuliani was more forgiving, saying at stop in Chicago, Ill., that “I respect his honesty ... I think that one of the things we need from our people who are running for office is not this pretense of perfection.

“The reality is all of us that run for public office, whether it's governor, legislator, mayor, president — we are all human beings. If we haven’t made mistakes, don’t vote for us because we've got some big ones that are going to happen in the future and we won't know how to handle them.”

Obama has written about his drug use before in his memoir, "Dreams from My Father."

"Junkie. Pothead. That's where I'd been headed: the final fatal role of the young would be black man," Obama wrote. Mostly he smoked marijuana and drank alcohol, Obama wrote, but occasionally he would snort cocaine when he could afford it.

Drugs, Obama wrote, were a way he "could push questions of who I was out of my mind, something that could flatten out the landscape of my heart, blur the edges of my memory."

But Obama rarely talks about the drug use on the campaign trail.

Before addressing the issue with the group of high school students Tuesday, Obama had fielded less personal questions about the war in Iraq and his education plan.

Obama, whose campaign was riding high Tuesday on the results of the latest Washington Post-ABC News poll that put him ahead of Hillary Clinton in early-voting Iowa, made the stop in Manchester to unveil his $18 billion education program.

The plan would expand teacher mentoring programs and reward teachers with increased pay not tied to standardized test scores. Failing teachers would be moved from classrooms and replaced with ones who are competent, Obama said.

FOX News' Bonney Kapp and The Associated Press contributed to this report.