To format the output of strings, you can use the string methods mentioned in "Finding out more about string methods," earlier in this chapter. But there is another, more common way to format strings: the % operator. When used with strings, this operator is sometimes called the interpolation operator.
When we use the word formatting, we aren't referring to word processor-type formatting —changing fonts, colors, styles, and the like. We mean specifying what happens when a value is inserted into a string. For example, we might specify how many digits to display to the right of a decimal point.
The interpolation operator also lets you insert data in specific places in a string. This means you can calculate your data in one part of your program and print it or save it to a file in another part.
Was this article helpful?