We covered the str
type at some length already in chapter two, but we'll take time now to explore its capabilities in a more depth.
As with any other Python sequence, we can determine the length of a string with the built-in len()
function.
>>> len("llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch") 58
The sign for the railway station at Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogo gogoch on the Welsh island of Anglesey – the longest place name in Europe:
Figure 5.1: The longest place name in Europe
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...