Monday, September 12, 2011

LPTHW - Exercise 10

In this exercise, we look at some more printing and escape characters. The "\" is the escape character in Python (just like in many other programming languages).



Extra Credit:

Escape characters are used to change the meaning of the character following it. For example \t will print the 'tab' character instead of 't'. All escape sequences supported by Python are listed on this page from the Python docs.

I tried replacing the triple double quotes in the example above with triple single quotes. When I ran the example, it ran just like the one with triple double quotes. I am not sure if there is any difference between them. Maybe if we use triple single quotes, then we can embed triple double quotes in them.

%s is better for printing because it is replaced by the String value, whereas %r is replaced by what is returned by the __repr function of the object (usually this is surrounded by double quotes).

No comments:

Post a Comment