Python‎ > ‎str‎ > ‎

str.format()

http://www.adilwaseem.com/

Definition
Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}').

Syntax
"{}.{}".format("x", "y")

Parameters
x & y=string

Examples
The two string values are positioned.
 >>> "{0} Research {1} ".format("Python", "Centre")
'Python Research Centre '
>>> 

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

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


Comments