> Message: 5
> Date: Fri, 04 Jul 2008 00:29:03 +0800
> From: Dong Li <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Question about string
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain
> 
> 
> > Date: Thu, 3 Jul 2008 10:18:23 +0100
> > From: "Alan Gauld" <[EMAIL PROTECTED]>
> > Subject: Re: [Tutor] Question about string
> > To: tutor@python.org
> > Message-ID: <[EMAIL PROTECTED]>
> > Content-Type: text/plain; format=flowed; charset="iso-8859-1";
> >       reply-type=original
> > 
> > 
> > "Dong Li" <[EMAIL PROTECTED]> 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" <[EMAIL PROTECTED]>
> > Subject: Re: [Tutor] Question about string
> > To: tutor@python.org
> > Message-ID:
> >       <[EMAIL PROTECTED]>
> > 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!

The string implicit string concatenation exist for things like verbose
re (regular expression):

import re
re.compile(
'<'     # Start opening tag
'\s*'   # Arbitrary whitespace
'(.*?)' # tagname
'\s*'   # Arbitrary whitespace
'(.*?)' # Values
'>',    # Start closing tag
re.VERBOSE
)

Without the implicit string concatenation, that re would have to be
written like this:

import re
re.compile(
'<'     + \  # Start opening tag
'\s*'   + \  # Arbitrary whitespace
'(.*?)' + \  # tagname
'\s*'   + \  # Arbitrary whitespace
'(.*?)' + \  # Values
'>',    # Start closing tag
re.VERBOSE
)

or in one long lines, and comment is thus impossible.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to