[Tutor] Question about string

Dong Li dongli2020 at gmail.com
Thu Jul 3 18:29:03 CEST 2008


> Date: Thu, 3 Jul 2008 10:18:23 +0100
> From: "Alan Gauld" <alan.gauld at btinternet.com>
> Subject: Re: [Tutor] Question about string
> To: tutor at python.org
> Message-ID: <g4i5h5$1cc$1 at ger.gmane.org>
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> 	reply-type=original
> 
> 
> "Dong Li" <dongli2020 at gmail.com> wrote
> 
> > I am new to python, so what I ask may be so basic. I don't know the
> > difference between
> >
> > s = 'a' 'b'
> > and
> > s = 'a'+'b'
> >
> > They have the same results. Thanks for relying!
> 
> I think the differencec is that the first is purely a syntax thing so
> the interpreter does the work of joining the strings together before
> processing the result as a single string whereas the second the
> two strings are treated separately and actual string addition
> (concatenation) is done which is a much more expensive
> operation in terms of computer power.
> 
> The first is only possible if you have literal strings but the second
> can be used for variables:
> 
> s1 = 'a'
> s2 = 'b'
> s = s1 s2     # doesn't work
> s = s1 + s2   # works
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld 
> 

> ------------------------------

> Date: Thu, 3 Jul 2008 09:53:07 +0000
> From: "Monika Jisswel" <monjissvel at googlemail.com>
> Subject: Re: [Tutor] Question about string
> To: tutor at python.org
> Message-ID:
> 	<e2f191310807030253p681550d0t76e69a4080055584 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Python is one of the smartest languages, it does many things for the
> programmer  (I don't know but this might be what they mean with
> Batteries-Included) , & you have just scratched the surface of it,  here
> python concatenated your strings together for you, later you will meet list
> comprehention & other stuff that actually does most of the programing logic
> for you for free.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20080703/9c54d12a/attachment-0001.htm>
> 
> ------------------------------

Thank you for excellent explanations! I have been attracted by python
more and more!



More information about the Tutor mailing list