6.00: Introduction to Computer Science and Programming
Getting Started: Python and IDLE
This recitation will cover how to set up Python and introduce you to IDLE, the Python development environment we will be using throughout this course.
Python should be set up correctly on the Linux athena machines. Type 'idle' at the command prompt to ensure that everything is working correctly. This should start up the Python development environment IDLE.
If you are working on your own machine, you will probably need to install Python. We will be using the standard Python software, available here. You should download and install version 2.5.4.
Windows:
Download and install: Windows Installer
Mac OS X:
Download and install: Mac OS X Installer.
Warning: On the Python homepage, the latest version available for download is actually 3.0. Do not install this! This version is not backwards compatible with the code that you'll be writing in this course (for example, you have to type print("test") instead of print "test"). Instead, be sure to download the version listed above.
IDLE is the standard Python development environment Its name is an acronym of "Integrated DeveLopment Environment". It works well on both Unix and Windows platforms.
It has a Python shell window, which gives you access to the Python interactive mode. It also has a file editor that lets you create and edit existing Python source files.
During the following discussion of IDLE's features, instead of passively reading along, you should start IDLE and try to replicate the screenshots.
When you start up IDLE, a window with an interactive Python shell will pop up:
You can type Python code directly into this shell, at the '>>>' prompt. Whenever you enter a complete code fragment, it will be executed. For instance, typing:
|
>>> print "hello world"
|
|
hello world
|
|
>>> 4+4
8 |
|
>>> import math
>>> math.sqrt(16) 4.0 |
|
>>> import math
>>> math.pow(3, 2) 9.0 >>> math.cos( 0 ) 1.0 |
--------
The tutorial for IDLE is based on the official IDLE
tutorial by Daryl Harms.
Asfandyar Qureshi, Feb 2006.
Edited by Vladimir Bychkovsky, Sept 2006.
Edited by Calvin On, Feb 2007.
Edited by Yang Zhang, Sep 2008.
Edited by Chih-yu Chao, Feb 2009.