[Tutor] Formatting a string
Alan Gauld
alan.gauld at btinternet.com
Tue Feb 1 16:08:18 CET 2011
"Becky Mcquilling" <ladymcse2000 at gmail.com> wrote
> Basically, I need to format a string as an example:
>
> "He is {what}.format("{wild}")
>
> I want to insert wild in place of what and output the resulting text
> WITH
> the curly braces.
>>> what = 'wild'
>>> "Here is {what}".format(what=what)
'Here is wild'
>>> "Here is {what}".format(what='wild')
'Here is wild'
>>> "Here is {{what}}".format(what='wild')
'Here is {what}'
>>> "Here is {what}".format(what='{wild}')
'Here is {wild}'
>>>
Take your pick :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list