Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77201
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: python string, best way to concat |
| Date | 2014-08-28 08:08 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-87A30C.08075228082014@news.panix.com> (permalink) |
| References | <55bab2a0-e0bc-4398-90b4-c9937498f5d8@googlegroups.com> <63bdccb4-9e34-4e40-b07d-14342e21815f@googlegroups.com> |
In article <63bdccb4-9e34-4e40-b07d-14342e21815f@googlegroups.com>,
peter <peter.mosley@talk21.com> wrote:
> I used to struggle with the concept of ''.join(('hello ','world')) - it
> seemed so convoluted compared with the intuitive 'hello '+'world', and I
> could never remember the syntax. Also, for the strings I was generally using
> the performance penalty was infinitesimal, so I was just adding complexity
> for the sake of the abstract concept of a more 'pythonic' style.
>
> Obviously this isn't going to change, but for concatenating short strings a
> and b is there any practical reason to avoid a+b?
For places where performance doesn't matter, string addition is just
fine. The computer works for you. If you're working for the computer,
you're doing something wrong.
That being said, join is typically used where you have a variable number
of strings in some iterable (e.g. a list of strings). For exactly two
strings, I would have probably written this as:
'%s %s' % (string1, string2)
and if I really wanted to use the join syntax, I would have moved the
delimiter (in this case, a space), into the first string:
' '.join([string1, string2])
Be aware of the various ways, then pick the one that works for you.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
python string, best way to concat dennisearlevans@gmail.com - 2014-08-27 13:31 -0700
Re: python string, best way to concat Dan Stromberg <drsalists@gmail.com> - 2014-08-27 15:30 -0700
Re: python string, best way to concat Peter Otten <__peter__@web.de> - 2014-08-28 00:34 +0200
Re: python string, best way to concat MRAB <python@mrabarnett.plus.com> - 2014-08-27 23:42 +0100
Re: python string, best way to concat Tim Chase <python.list@tim.thechases.com> - 2014-08-27 17:44 -0500
Re: python string, best way to concat Chris Angelico <rosuav@gmail.com> - 2014-08-28 08:55 +1000
Re: python string, best way to concat Peter Otten <__peter__@web.de> - 2014-08-28 00:59 +0200
Re: python string, best way to concat MRAB <python@mrabarnett.plus.com> - 2014-08-28 08:12 +0100
Re: python string, best way to concat peter <peter.mosley@talk21.com> - 2014-08-28 01:30 -0700
Re: python string, best way to concat Marko Rauhamaa <marko@pacujo.net> - 2014-08-28 11:34 +0300
Re: python string, best way to concat Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-28 09:43 +0100
Re: python string, best way to concat Chris Angelico <rosuav@gmail.com> - 2014-08-28 18:58 +1000
Re: python string, best way to concat Roy Smith <roy@panix.com> - 2014-08-28 08:08 -0400
Re: python string, best way to concat Mihamina Rakotomandimby <mihamina.rakotomandimby@rktmb.org> - 2014-08-28 15:19 +0300
Re: python string, best way to concat Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-28 15:48 +0100
csiph-web