lambdamusic
2/7/2013 - 9:27 PM

Python: Python: formatting strings

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