This “quick start” section is intended to “flash” Python to you so that any constructs recognized from previous programming
experience can be used for your immediate needs. The details will be spelled out in succeeding chapters, but a high-level
tour is one fast and easy way to get you into Python and show you what it has to offer. The best way to follow along is to
bring up the Python interpreter in front of you and try some of these examples, and at the same time you can experiment on
your own.

We introduced how to start up the Python interpreter in Chapter 1 as well as in the exercises (Problems 1-4). In all interactive examples, you will see the Python primary ( >>> ) and secondary ( ... ) prompts. The primary prompt is a way for the interpreter to let you know that it is expecting the next Python statement,
while the secondary prompt indicates that the interpreter is waiting for additional input to complete the current statement.

You will notice two primary ways that Python “does things” for you: statements and expressions (functions, equations, etc.).
Most of you already know the difference between the two, but in case you need to review, a statement is a body of control
which involves using keywords. It is similar to issuing a command to the interpreter. You ask Python to do something for you,
and it will do it. Statements may or may not lead to a result or output. Let us use the print statement for the programmer’s perennial first example, Hello World:

>>> print 'Hello World!'
Hello World!

Expressions, on the other hand, do not use keywords. They can be simple equations that you use with mathematical operators,
or can be functions which are called with parentheses. They may or may not take input, and they may or may not return a (meaningful)
value. (Functions that do not explicitly return a value by the programmer automatically return None, Python’s equivalent to NULL.) An example of a function that takes input and has a return value is the abs() function, which takes a number and returns its absolute value is:

>>> abs(4)
4
>>> abs(-4)
4

We will introduce both statements and expressions in this chapter. Let us continue with more about the print statement.

2.1 Program Output, the print Statement, and “Hello World!”

In some languages, such as C, displaying to the screen is accomplished with a function, e.g., printf(), while with Python and most interpreted and scripting languages, it is a statement. Many shell script languages use an echo command for program output.

Core Note: Dumping variable contents in interactive interpreter

Usually when you want to see the contents of a variable, you use theprintstatement in your code. However, from within the interactive interpreter, you can use theprintstatement to give you the string representation of a variable, or just dump the variable raw—this is accomplished by simply
giving the name of the variable.

In the following example, we assign a string variable, then useprintto display its contents. Following that, we issue just the variable name.

Notice how just giving only the name reveals quotation marks around the string. The reason for this is to allow objects other
than strings to be displayed in the same manner as this string—being able to display a printable string representation of any object, not just strings. The quotes are there to indicate that the object whose value you just dumped to the display is a
string. Once you become more familiar with Python, you will recognize that str() is used for print statements, while repr() is what the interactive interpreter calls to display your objects.

The underscore (_) also has special meaning in the interactive interpreter: the last evaluated expression. So after the code above has executed,
_ will contain the string:

%s means to substitute a string while %d indicates an integer should be substituted. Another popular one is %f for floating point numbers. We will see more examples throughout this chapter. Python is fairly flexible, though, so you
could pass in a number to %s without suffering any consequences with more rigid languages. See Section 6.4.1 for more information on the string format operator.

The print statement also allows its output directed to a file. This feature was added way back in Python 2.0. The >> symbols are used
to redirect the output, as in this example with standard error: