The royal patriarch said it was "a great pleasure to be back in circulation" as he handed out medals at the Royal Society of Edinburgh (RSE), Scotland's national academy of science and letters.
Prince Philip, known as the Duke of Edinburgh, spent 11 nights in June at the private London Clinic, where he had unspecified "exploratory" abdominal surgery.
Palace officials confirmed when he left the clinic on June 17 that he would take two months off to recover from the surgery.
Philip was applauded as he arrived and gave a brief wave before meeting dignitaries outside the venue.
Making a spontaneous address inside, he said: "It's a great pleasure to be back in circulation again."
Referring to the medal-winners, the duke joked: "I wish to God I could understand what they'd been doing!"
RSE president John Arbuthnott said: "We deeply appreciate the interest Prince Philip has shown in the society during over 60 years of honorary fellowship and are particularly delighted to see his royal highness here in what has been an eventful year for the royal family."
Famed for his off-the-cuff quips, Prince Philip, who married Elizabeth in 1947, is the longest-serving royal consort in British history.
The queen, 87, once described him as "my strength and stay all these years".
He will now join his family at Balmoral, the queen's private residence in Scotland, where the royals traditionally spend their summer break.
