String manipulation
There are three major methods for inserting variables into strings. Each has different advantages and disadvantages of a technical nature. It's good to know about all three, as they have uses beyond our needs here, so let's review them.
String manipulation method 1: string addition
String addition seems like an odd concept at first, as it would not seem possible to "add" strings together, unlike integers or floats which are numbers. However, within Python and other programming languages, this is a normal step. Using the plus sign "+
", strings are "added" together to make longer strings, or to allow variables to be added into the middle of existing strings. Here are some examples of this process:
>>> aString = "This is a string" >>> bString = " and this is another string" >>> cString = aString + bString >>> cString
The output is as follows:
'This is a string and this is another string'
Two or more strings can be "added" together, and...