A quine is a program whose only output is its own source. The trick is always the same: keep the text of the program as data, and write code that prints that data twice, once as a quoted string and once as itself.
Here %r asks Python for the quoted representation of the string, so the first half of the output comes out with its own quotes, and the %% becomes a single % so the second half comes out as code. Paul Bratley and Jean Millo studied self-reproducing programs in 1972 in SNOBOL, Lisp, Fortran, and ALGOL 60, and Hamish Dewar had written one in Atlas Autocode at Edinburgh in the 1960s. Douglas Hofstadter named them in Gödel, Escher, Bach in 1979 after the philosopher W. V. O. Quine, who studied sentences that talk about themselves. Nobody owns this one; thousands of people have retyped it to see the trick work. It is the smallest demonstration that a program can contain a description of itself, which is also the idea at the bottom of Gödel's proof and of the Lisp apply in the previous room.