Formatting.py

>>> template = '{0}, {1} and {2}' # By position >>> template.format('spam', 'ham', 'eggs') 'spam, ham and eggs' >>> template = '{motto}, {pork} and {food}' # By keyword >>> template.format(motto='spam', pork='ham', food='eggs') 'spam, ham and eggs' >>> template = '{motto}, {0} and {food}' # By both >>> template.format('ham', motto='spam', food='eggs') 'spam, ham and eggs' >>> template = '{}, {} and {}' # By relative position >>> template.format('spam', 'ham', 'eggs') # New in 3.1 and 2.7 'spam, ham and eggs'
String Formatting Method Calls. Formatting Method Basics.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.