If the formatting (white space, new lines, indentation) of the code matters, use the pre element in combination with the code element:

<pre>
    <code>
    x = 42
    if x == 42:
        print "x is …          … 42"
    </code>
</pre>

You still have to escape characters with special meaning in HTML (like \\< with &lt;), so for displaying a block of HTML code (<p>This is a paragraph.</p>), it could look like this:

<pre>
    <code>
    &lt;p>This is a paragraph.&lt;/p>
    </code>
</pre>