[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
BeginnersGuideToPython_Introduction

Beginner's Guide To Python, Introduction

First things first

The first thing you should do is download and install the most recent version of Python for your operating system. Once you have Python installed, there are two ways it can be used: interactively or by writing scripts. Let's start with the interactive interpreter to get a feel for Python.

Starting the Python Interpreter

Once you have Python installed, using it is as easy as starting up any other program. If you are using a command line you need to make sure that the Python directory is in your PATH environment variable. If you are using Windows, you can start the Python interpreter from the Start Menu. If you select "Python Command Line" you will get a DOS Window with the Python interpreter running. Windows users might be more comfortable running the  ?IDLE program because it is graphical and therefore regular  ?menu and mouse commands are available.

Once you successfully get the interpreter running, you should see something like this (the specific text will vary by platform and whether you are running a graphical or text based version):
Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 


The '>>>' symbol is Python's default prompt.

Using the Python Interpreter Interactively

When you have started the Python interpreter in interactive mode, you can enter commands one at a time and examine the results. This is often useful for testing new ideas or exploring new modules. Here is an example session with the interactive interpreter:

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1
1
>>> a = 1
>>> a
1
>>> a + a
2
>>> a + 2
3
>>> a = 2
>>> a
2
>>> a**a
4
>>> 


As the user, you enter commands at the prompt (>>>) and Python displays the results (if any) of the commands. In Python, you define a variable by using it. You don't have to declare a variable and you never specify a data type. Python is smart enough to figure out if your variable contains a number, string, list, object, function, or any other valid type! If you never wrote a Python script, you could at least use the interpreter as a fully-functional desktop calculator!

To exit the interpreter, you enter an end-of-file character (usually control-d, but might be control-z on Windows machines, depending on how you are using the interpreter).

last edited (April 5, 2003) by DragonSlayah, Number of views: 10663, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.