[Tutor] String Replacement question

Wolfram Kraus wolfram.kraus at fen-net.de
Wed May 21 12:11:28 CEST 2008


Am 21.05.2008 11:35, Faheem schrieb:
> Hi all,
>  How do I replace the same value multiple times without repeating the
> same variable name/value repeatedly?
> for ex.  
> 
>  some = 'thing' 
>  print '%s %s %s %s' % (some,some,some,some)
> 
> in this case, my question is how do i replace "% (some,some,some)" with
> something more concise?
> 
> thanks in advance,
> Faheem

Hi!

Two possible solutions:

print "%s %s %s %s" % (tuple([some]*4))

print " ".join([some for x in range(4)])

HTH,
Wolfram



More information about the Tutor mailing list