4.4 Creating strings
We’ve now seen many examples where we have entered literal strings between single, double, or triple quotes. Let’s look at additional methods to construct strings. You always create new strings and you cannot modify the originals.
letters = "abcd"
letters + "efg"
'abcdefg'
letters
'abcd'
letters += "efg"
letters
'abcdefg'
The “+
” operator concatenates two strings. “Concatenate” is a
fancy word meaning “stick them together, one after the other.” You can assign the new value to
the variable or use operator assignment, as I did here.
String concatenation is very powerful, allowing you to mix text with other strings and other data types.
brands = [
"Fender",
"Gibson",
"Ibanez"
]
"I own "...