Literals

We've been using literals since Chapter 1, but we didn't call them that. The term is computerspeak for a constant value; that is, what you type is literally what you get. In the following interactive session, for example, the literals are "Hello World", 100, 3200000000000L, and 3.5.

>>> a_literal_string = "Hello World"
>>> a_literal_integer = 100
>>> a_literal_long = 3200000000000L
>>> a_float_literal = 3.5

Literals can be contained in statements.

print ("Hello I am a literal string")
Table 2-1. Escape Sequence Characters
Character Meaning
\\ Backslash
\' Single quote
\" Double quote
\a ASCII Bell (BEL)
\b ASCII Backspace (BS)
\f ASCII Formfeed (FF)
\n ASCII Linefeed (LF)
\r ASCII Carriage return (CR)
\t ASCII Horizontal tab (TAB) ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.