"We are heartbroken by the loss of life," he said after his tour.
Mr Obama dismissed criticism that he arrived too late and praised state officials for their initial response.
The president also met the family of Alton Sterling and the families of the Baton Rouge police officers killed last month.
Mr Sterling, a black man, was killed at the hands of a white police officer in Baton Rouge.
His death, along with the police killing of Philando Castile in St Paul, Minnesota, stoked racial tensions and led to protests across the country.