Hey All,
Thanks..
That was quick. Good to know there is a mailing list like this one.
Thanks to everyone and all the replies.
Faheem
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
> > some = 'thing'
> > print '%s %s %s %s' % (some,some,some,some)
>
> You can use named parameters, which moves the repetition to the format string:
>
> In [24]: print '%(some)s %(some)s %(some)s %(some)s' % (dict(some=some))
> thing thing thing thing
>
> With multiple values, a common trick
Faheem wrote:
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 concis
Faheem wrote:
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 concis
On Wed, May 21, 2008 at 9:39 AM, Jeff Younker <[EMAIL PROTECTED]> 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.
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
-jeff
___
Moishy Gluck wrote:
>>> "%s " %st*3
'String String String '
^
If you look closely at the end of the string there is an extra space.
>>> " ".join((st, )*3)
'String String String'
^
No extra space.
Ah...Okay!
On Wed, May 21, 2008 at
uot; %st*3
>>>>>
>>>> String String String
>>
>>>
>>>>>
>> Does this help?
>>
>> Kinuthia...
>>
>> -
>>
>> Message: 6
>> Date: Wed, 21 May 2008 15:05:21 +0530
>
st = "String"
print "%s " %st*3
String String String
Does this help?
Kinuthia...
-
Message: 6
Date: Wed, 21 May 2008 15:05:21 +0530
From: Faheem <[EMAIL PROTECTED]>
Subject: [Tutor] String Replacement question
To: tutor@python.org
Mes
Some other solutions might be
>>> animal = 'cat'
>>> " ".join((animal, ) * 4)
'cat cat cat cat'
>>> animal = 'cat'
>>> print " ".join((animal, ) * 4)
cat cat cat cat
>>>#If you need the string injected into another string
>>> print "My %s's name is ginger." % (" ".join((animal,) * 4))
My cat cat c
On Wed, May 21, 2008 at 5:35 AM, Faheem <[EMAIL PROTECTED]> wrote:
> 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)
You can use named parameters, whi
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)" wit
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 adv
13 matches
Mail list logo