Tips for writing quines A quine is a program that produces output that's identical to the program's source code. On this website, we generally only care about proper quines (at the time of writing, the current definition is "some part of the output is encoded by a different part of the program").

What advice do you have for writing proper quines, or programs with quine-like properties? As usual, each tip should be in a different answer.
Take advantage of string formatting
One of the easiest ways to create a quine is to define a string, then put the string inside itself with string formatting.

s='s=%r;print s%%s';print s%s



So in this example Python quine, we declare a string with the first part equal to whatever is before the string s=, then we allow for the string to be inserted with formatting with %r, and finally we put what comes after the string to print and format it. The trailing newline is because print prints a trailing newline.
So the template is really this, in Python:
&lt;A&gt;'&lt;A&gt;%r&lt;B&gt;'&lt;B&gt;

To expand the existing quine with more code:
&lt;more A&gt;s='&lt;more A&gt;s=%r;print s%%s&lt;more B&gt;';print s%s&lt;more B&gt;