Return to Snippet

Revision: 21871
at December 22, 2009 15:34 by magicrebirth


Initial Code
>>>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

Initial URL


Initial Description
Python allows for strings to be formatted using a predefined format string with a list of variables. 
The following is an example of using multiple format strings to display the same data:

Initial Title
Python: formatting strings

Initial Tags
format

Initial Language
Python