Intro

Intro next up previous contents
Next: Hello, World Up: Non-Programmers Tutorial For Python Previous: Contents   Contents

Subsections

First things first

So, you've never programmed before. As we go through this tutorial I will attempt to teach you how to program. There really is only one way to learn to program. You must read code and write code. I'm going to show you lots of code. You should type in code that I show you to see what happens. Play around with it and make changes. The worst that can happen is that it won't work. When I type in code it will be formatted like this:

##Python is easy to learn
print "Hello, World!"

That's so it is easy to distinguish from the other text. To make it confusing I will also print what the computer outputs in that same font.

Now, on to more important things. In order to program in Python you need the Python software. If you don't already have the Python software go to http://www.python.org/download/ and get the proper version for your platform. Download it, read the instructions and get it installed.

Installing Python

First you need to download the appropriate file for your computer from http://www.python.org/download. Go to the 2.0 link (or newer) and then get the windows installer if you use Windows or the rpm or source if you use Unix.

The Windows installer will download to file. The file can then be run by double clicking on the icon that is downloaded. The installation will then proceed.

If you get the Unix source make sure you compile in the tk extension if you want to use IDLE.

Interactive Mode

Go into IDLE (also called the Python GUI). You should see a window that has some text like this:
Python 2.0 (#4, Dec 12 2000, 19:19:57)
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>>
The >>> is Python way of telling you that you are in interactive mode. In interactive mode what you type is immediately run. Try typing 1+1 in. Python will respond with 2. Interactive mode allows you to test out and see what Python will do. If you ever feel you need to play with new Python statements go into interactive mode and try them out.


Creating and Running Programs

Go into IDLE if you are not already. Go to File then New Window. In this window type the following:
print "Hello, World!"

First save the program. Go to File then Save. Save it as hello.py. (If you want you can save it to some other directory than the default.) Now that it is saved it can be run.

Next run the program by going to Run then Run Module (or if you have a older version of IDLE use Edit then Run script). This will output Hello, World! on the *Python Shell* window.

Confused still? Try this tutorial for IDLE at http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

Using Python from the command line

If you don't want to use Python from the command line, you don't have too, just use IDLE. To get into interactive mode just type python with out any arguments. To run a program create it with a text editor (Emacs has a good python mode) and then run it with python program name.


next up previous contents
Next: Hello, World Up: Non-Programmers Tutorial For Python Previous: Contents   Contents
Josh Cogliati jjc@honors.montana.edu Wikibooks Version: Wikibooks Non-programmers Python Tutorial Contents