"While filming the last scene of Monty Python's Life of Brian, the cast were bored and hot sitting up on their crucifixes. So Eric Idle started singing a little ditty. Everyone (but Eric) liked it so much that they decided to use it.
Hmm, the Wikipedia version differs from the one that Eric gave during the Monty Python anniversary special. In that special, which I have on tape, Eric explains that they needed a closer for the movie. He came up with the song, "Always look on the bright side of life", and everyone hated it. "I sang it very straight," said Eric. "They just didn't think it was funny."
Eric was also playing a character called Mr. Cheeky. He's the guy who gets saved at the end by being a wiseacre. Anyway, Mr. Cheeky used a Cockney accent. Eric came up with the idea of applying a Cockney accent to his song and, bingo, it suddenly worked. That's why this character pops out of nowhere at the end, and starts singing the lyrics with the accent that we all recognize.
Eric also told a very moving story about that song. During the Falklands Islands battles, one of the British ships was damaged and was sinking. The crew, awaiting rescue for a couple of hours at least, started to sing "Always look on the bright side of life". Eric said that was the most flattering tribute he ever had in his life.