Strings Concatenation with (+)


>>> 'spaish' + 'inquisition'
>>> 'spanich' + ' ' + 'inquisition'
'spanich inquisition'
>>> s = 'spanish' + ' ' + 'inquition' + 'made easy'
>>> s
'spanish inquitionmade easy'
>>> import string
>>> string.upper(s[:3] + s[20])

The last example illustrates using the concatenation operator to put together a pair of slices from string s, the “Spa” from “Spanish” and the “M” from “Made.” The extracted slices are concatenated and then sent to the string.upper() function to convert the new string to all uppercase letters.


You may also like...