Minor, minor style question

Martijn Faassen m.faassen at vet.uu.nl
Tue Mar 5 07:13:48 EST 2002


Cameron Laird <claird at starbase.neosoft.com> 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?
> -- 

Note that a very pleasant alternative for strings in Python is:

s = ("abc "
     "def "
     "xyz")


Frequently the brace context is already taken care of anyway, such
as in function calls:

f("foo "
  "bar "
  "baz", 1, 15)

Generally I try to avoid \ using tricks like this, though I'm not religious
about it. Sometimes a backslash is nicest.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list