MEMPHIS - The graduating class of Booker T. Washington High School was getting a last-minute pep talk from its principal, Alisha Kiner, on Monday, just before the ceremony began, when an out-of-town visitor dropped by to offer his own words of encouragement.

"You inspire me," President Obama told the 155 students, who stopped flicking the tassels on their green and gold mortar boards to give him a deafening cheer. "That's why I'm here."

Obama later addressed the class of 2011 in a more formal fashion, delivering a commencement speech in which he emphasized the importance of education in a competitive world. He spoke in personal terms of how it had transformed his own life. And he praised the students of this historically black high school, many of whom struggled with poverty and broken homes, for earning a diploma.

"Yes, you're from South Memphis," Obama said to the enthusiastic audience at the Memphis convention center. "Yes, you've always been underdogs. No one has handed you a thing. But that also means that whatever you accomplish in your lives, you will have earned it."

Booker T. Washington earned the privilege of having the president as its speaker by winning the White House's Race to the Top challenge, which is designed to reward improvement in graduation rates. In 2010, nearly 82 percent of the school's students graduated, compared with 51 percent in 2005 -- even as the neighborhood around the school frayed economically and the number of its students living under the poverty line rose.

The president's four-hour visit to Memphis allowed Obama to highlight one of his major domestic initiatives, secondary education, as well as offer sympathy to victims of the recent flooding of the Mississippi River. Last week Obama declared 15 Tennessee counties federal disaster areas, making them eligible for aid money.

Before the graduation ceremony, the president sat down for 35 minutes with a roundtable gathering of victims, as well as emergency workers and local officials. The disaster, however, did little to dampen the mood at the graduation, which featured a jazz band and the singing of "I Am One," an unofficial anthem for the school. There were several student speakers, one of whom rivaled Obama for timing and smooth delivery.

Christopher Dean, a senior who introduced the president, said his job was difficult because everyone already knew the speaker's occupation and the name of his wife.

"Or," Dean said, after pausing for a beat, "where he was born."

Obama bent over in laughter.