Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Created February 7, 2013 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdamusic/4734370 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734370 to your computer and use it in GitHub Desktop.
Python: Python: formatting strings
>>>list = ["Brad", "Dayley", "Python Phrasebook",
2006]
>>>letter = """
>>>Dear Mr. %s,\n
>>>Thank you for your %s book submission.
>>>You should be hearing from us in %d."""
>>>display = """
>>>Title: %s
>>>Author: %s, %s
>>>Date: %d"""
>>>record = "%s|%s|%s|%08d"
>>>print letter % (list[1], list[2], list[3])
Dear Mr. Dayley,
Thank you for your Python Phrasebook book submission.
You should be hearing from us in 2006.
>>>print display % (list[2], list[1], list[0],
list[3])
Title: Python Phrasebook
Author: Dayley, Brad
Date: 2006
>>>print record % (list[0], list[1], list[2],
list[3])
Brad|Dayley|Python Phrasebook|00002006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment