Minor, minor style question
Sean 'Shaleh' Perry
shalehperry at attbi.com
Fri Mar 1 11:54:01 EST 2002
On 01-Mar-2002 Cameron Laird wrote:
> Why would I prefer
> string = ""
> string = string + "abc "
> string = string + "def "
> string = string + "xyz"
> over
> string = "abc " + \
> "def " + \
> "xyz"
> ? I see a lot of the former in contexts I associate
> with Visual Basic- or JavaScript-majority folkways.
> Is there an attraction to the redundancy (and fragil-
> ity!) I'm missing? Are \-s *so* deprecated?
According to posts by people like Tim Peters the preferred idiom is more like:
l = ["abc", "def", "xyz"]
s = string.join("", l)
i.e. build up a list of pieces through out the function and then join() them at
the end.
More information about the Python-list
mailing list