[Tutor] String Replacement Question

Carlos Hanson carlos.hanson at gmail.com
Wed May 21 19:15:17 CEST 2008


On Wed, May 21, 2008 at 9:39 AM, Jeff Younker <jeff at drinktomi.com> wrote:
> On May 21, 2008, at 6:42 AM, Kinuthia Muchane wrote:
>
>>>>> st = "String"
>>>>> print "%s " %st*3
>>
>> String String String
>>>>>
>>
>> Does this help?
>
> Another approach is to use dictionaries for string
> replacement.
>
>>>> subst = {'some': 'thing'}
>>>> print "%(some)s%(some)s%(some)s"  % subst
> thingthingthing
>

As an alternate to repeating the formated string:

--> print '%(some)s'*3 % subst
thingthingthing

(forgot to reply all)

-- 
Carlos Hanson


More information about the Tutor mailing list