Concatenating strings

Concatenation of strings is supported using the plus operator:

>>> "New" + "found" + "land"
Newfoundland

Also the related augmented assignment operator:

>>> s = "New"
>>> s += "found"
>>> s += "land"
>>> s
'Newfoundland'

Newfoundland, the sixteenth largest island in the world, is one of relative few closed, triple-compound words in English:

Figure 5.2: Newfoundland

Remember that strings are immutable, so here the augmented assignment operator is binding a new string object to s on each use. The illusion of modifying s in place is achievable because s is a reference to an object, not an object itself. That is, although the string itself is immutable, the reference to it is mutable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset