[Tutor] Concatenating Strings

Steve Willoughby steve at alchemy.com
Tue May 29 04:07:20 CEST 2012


On 28-May-12 19:00, Jeremy Duenas wrote:
> and the both printed the same output……so why would I want to use ‘+’ to
> add strings if there seems to be no reason too?

Juxtaposing strings only works with constants, which may be convenient
in some cases, but it won't work at all when concatenating other string 
values.

a="hello"
b="world"

a+b    # will yield "helloworld" but
a b    # is a syntax error

Using + is arguably preferable when you have a choice to make, since it 
works in all cases, including constants.

-- 
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C


More information about the Tutor mailing list