Stringing Them Along

Inside Python, a string literal is surrounded by quotation marks, which distinguish it from other kinds of data, such as integers or names. You see the quotation marks when you type the name of a string in the interpreter. But when you print a string, the quotation marks don't appear.

TECHNICAL The Python interpreter calls repr() to display the result of an STUFF expression—this display itself is usually a valid expression. The print statement uses str(), which displays a "prettier" version. (Chapter 2 has more details.)

The following sections describe several ways to quote strings and how to use special characters inside strings (or how not to use them).

Was this article helpful?

0 0

Post a comment