Created
May 22, 2017 11:24
-
-
Save chrisbay/19aaa7f26589a01a580cef5b9b864d23 to your computer and use it in GitHub Desktop.
Examples of using string.format to create HTML snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
super useful to review this for last portion of web-caesar. thanks!