Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Using the interpreter prompt

Start the intepreter on the command line by entering python at the shell prompt. Now enterprint 'Hello World' followed by the Enter key. You should see the wordsHello World as output.

For Windows users, you can run the interpreter in the command line if you have set the PATH variable appropriately. Alternatively, you can use the IDLE program. IDLE is short for Integrated DeveLopment Environment. Click on Start -> Programs -> Python 2.3 -> IDLE (Python GUI). Linux users can use IDLE too.

Note that the <<< signs are the prompt for entering Python statements.

Example 3.1. Using the python interpreter prompt

$ python
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information. >>> print 'hello world'
hello world
>>>

Notice that Python gives you the output of the line immediately! What you just entered is a single Python statement. We useprint to (unsurprisingly) print any value that you supply to it. Here, we are supplying the textHello World and this is promptly printed to the screen.

How to quit the Python prompt

To exit the prompt, press Ctrl-d if you are using IDLE or are using a Linux/BSD shell. In case of the Windows command prompt, press Ctrl-z followed by Enter.