In the Python shell, type the string,
"Rock a by baby,\n\ton the tree top,\t\when the wind blows\n\t\t\t the cradle will drop." Feel free to experiment with the number of
\t escape sequences to see how this affects what gets displayed on your screen. You can even try changing their placement. What do you think you are likely to see?
In the Python shell, use the same string indicated in Exercise 1, but this time, display it using the
print() function. Once more, try differing the number of
\t escape sequences. How do you think it will differ?
'Rock a by baby,\n\ton the tree top,\t\twhen the wind blows\n\t\t\t the cradle will drop.'
Because this is not being printed, the special characters (those preceded with a backslash) are not translated into a form that will be displayed differently from how you typed them.
Rock a by baby, on the tree top, when the wind blows the cradle will drop.
When they are printed, "
\n" and "
\t" produce a newline and a tab character, respectively. When the
print() function is used, it will render them into special characters that don't appear on your keyboard, and your screen will display them.
Do the following first three exercises in Notepad and save the results in a file called
ch2_exercises.py. You can run it from within Python by opening the file and choosing Run Module.
In the Python shell, multiply 5 and 10. Try this with other numbers as well.