quotation. Listing 4.4 shows an example of protecting a quote, using single quotes in the argument.
LISTING 4.4 Protecting a Double Quote with Single Quotes
Click here to view code image
>>> print ('I said, "I need to protect my quotation!" and did so.')
I said, "I need to protect my quotation!" and did so.
>>>
Did You Know: Protecting Single Quotes with Single Quotes
You can also embed single quotes within single quote marks and double quotes within
double quote marks. However, when you do, you need to use something called an
“escape sequence,” which is covered later in this hour.
Formatting Output with the print Function
You can perform various output formatting features by using the print function. For example, you
can insert a single blank line by using the print function with no arguments, like this:
print ()
The screen in Figure 4.1 shows a short Python script that inserts a blank line between two other lines
of output.
FIGURE 4.1 Adding a blank line in script output.
Another way to format output using the print function is via triple quotes. Triple quotes are simply
three sets of double quotes.
Listing 4.5 shows how you can use triple quotes to embed a linefeed character by pressing the Enter
key. When the output is displayed, each embedded linefeed character causes the next sentence to
appear on the next line. Thus, linefeed moves your output to the next new line. Notice that you cannot
see the linefeed character embedded on each line in the code; you can only see its effect in the output.
LISTING 4.5 Using Triple Quotes
Click here to view code image