About half of the student body, chosen by lottery, heard the speech in person - the rest watched the way students around the country did, by live web stream.
In attendance were a host of local dignitaries, including Gov. Rendell, Mayor Nutter, Rep. Bob Brady, Rep. Chaka Fattah, Rep. Allyson Schwartz, and Schools Superintendent Arlene Ackerman.
Obama said he wasn't always a strong student as a young man. He recalled a tough conversation that he had with his mother on the subject.
"It was about how my grades were slipping, how I haven't even started my college applications, how I was acting, as she put it, 'casual' about my future. It's a conversation I suspect will sound familiar to some of the students and parents here today," the president said.
Her words had a strong effect on Obama, and his grades improved.
"And I know that if hard work could make the difference for me, it can make the difference for you, too," said Obama.
Obama hailed Masterman as "one of the best schools in Philadelphia - a leader in helping students succeed in the classroom" and mentioned that it was just named a 2010 National Blue Ribbon School for its standout academics.
The president also made mention of school violence and bullying.
"There are neighborhoods in my hometown of Chicago, where kids have hurt one another," Obama said. "And the same thing has happened here in Philly."
On December 3, about 30 Asian students were injured and seven required hospital treatment after they were attacked by groups of mostly African American students at South Philadelphia High. A district investigation concluded that race was a contributing factor in the attacks.
Obama told the students that "life is precious, and part of its beauty lies in its diversity. We shouldn't be embarrassed by the things that make us different. We should be proud of them."
On his way to Philadelphia with Obama, U.S. Secretary of Education Arne Duncan this morning praised the Philadelphia School District for its test score growth and for Superintendent Arlene Ackerman's ambitious plan to improve the lowest performing schools.
For the first time since Pennsylvania has been keeping tabs under No Child Left Behind, more than half of city students met state standards in reading and math this year.
"I think the progress we're seeing in Philadelphia is outstanding. The progress is real. Many things are going in the right direction," Duncan said in a telephone interview. "The superintendent is doing a fantastic job. I'm a big fan of hers."
He acknowledged that Ackerman's plan to pump lots of resources into six "promise academy" schools may seem high risk to some, but really is the best decision.
"What we're doing for children isn't good enough," he said. "Her willingness to challenge the status quo and put resources behind the schools and communities that are struggling . . . is absolutely the right thing to do. For far too long, we've sat idly by with a disturbing sense of complacency and watched children fail."
While Duncan and Obama are visiting one of the best schools in the district and the state – Masterman, a prestigious magnet that draws the top students from around the city – Duncan said high school performance remains a major problem in many cities across the country, including Philadelphia.
"At the end of the day, that's the toughest and most important battle," he said. Of Philadelphia, he said: "What I appreciate is the honesty of the conversation and the willingness and desire to get dramatically better."
Asked about the problems at South Philadelphia High School, Duncan said: "From any difficult situation, you hope it never happens again and I hope some lessons were learned and some good comes from it. It's tragic that you have students in that situation, but you have to deal with the issues openly and honestly and you have to be sure the district emerges stronger . . . I have a lot of confidence that the district is committed to doing that."
Contact staff writer Kristen Graham at 215-854-5146 or email@example.com.