Skip to content

Instantly share code, notes, and snippets.

@chrisbay
Created May 22, 2017 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbay/19aaa7f26589a01a580cef5b9b864d23 to your computer and use it in GitHub Desktop.
Save chrisbay/19aaa7f26589a01a580cef5b9b864d23 to your computer and use it in GitHub Desktop.
Examples of using string.format to create HTML snippets
# Using indexed placeholders
markup = """
<!doctype html>
<html>
<head>
<title>{0}</title>
</head>
<body>
<h1>{0}</h1>
</body>
</html>
"""
markup = markup.format('My Page Title', 'My Page Heading')
print(markup)
# Using named placeholders
markup = """
<!doctype html>
<html>
<head>
<title>{title}</title>
</head>
<body>
<h1>{heading}</h1>
</body>
</html>
"""
markup = markup.format(title='My Page Title', heading='My Page Heading')
print(markup)
@goosenoose
Copy link

super useful to review this for last portion of web-caesar. thanks!

@ktown5422
Copy link

ktown5422 commented Jun 15, 2019

Good review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment