[Tutor] working with strings in python3

Westley Martínez anikom15 at gmail.com
Mon Apr 18 20:58:53 EDT 2011


On Tue, 2011年04月19日 at 10:34 +1000, James Mills wrote:
> On Tue, Apr 19, 2011 at 10:17 AM, Rance Hall <ranceh at gmail.com> wrote:
> > pseudo code:
> >
> >
> > message = "Bah."
> >
> > if test:
> > message = message + " Humbug!"
> >
> > print(message)
> >
> > end pseudo code
>> Normally it's considered bad practise to concatenate strings.
> Use a a format specifier like this:
>> > message = "Bah."
> >
> > if test:
> > message = "%s %s" (message, " Humbug!")
> >
> > print(message)
>> Python3 (afaik) also introduced the .format(...) method on strings.
>> cheers
> James
>> -- 
> -- James Mills
> --
> -- "Problems are solved by method"

How is concatenating strings bad practice? I use code such as:
string = 'hello'
string += ' children.'
a lot.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /