First page Back Continue Last page Overview Graphics

Exercise: HTML Tags

Rewrite the previous example, so that an arbitrary string will be surrounded by an opening and closing tag:

Example:

<h1>

My string!

</h1>

from contextlib import contextmanager

@contextmanager

def tag(name):

print("<%s>" % name)

yield

print("</%s>" % name)

with tag("h1"):

print("My string!")