Python‎ > ‎string constants‎ > ‎

string.Formatter

http://www.adilwaseem.com/

Introduction
Format the string according defined order.

Syntax
string.Formatter().format "{0},{1},{2}", "s","s", "s")

Parameters
s=string

Import module
Importing module is required in the Shell window and the Editor window.

Examples
The method format the string into the position.
 >>> string.Formatter().format("{0} {1} {2}", "Python", "Research", "Centre")
'Python Research Centre'
>>> string.Formatter().format("{1} {2} {0}", "Python", "Research", "Centre")
'Research Centre Python'
>>>

The string is formatted through str.format.
 >>> "{0} Research {1} ".format("Python", "Centre")
'Python Research Centre '
>>> 

The strings are formatted in two positions through through str.format.
 >>> "{} {}".format("Python", "Lake")
'Python Lake'
>>> 

Comments