Windows - Start → All Programs → Python 3.2 → IDLE
DEMO - opening IDLE
Starting IDLE Continued
When you first open IDLE, you should see a window titled "Python Shell"
to reiterate, the Python Shell is for entering and running programs line-by-line
sometimes the shell can be referred to as the Python interpreter, console or interactive shell
you'll probably want to start out by creating a new file…
Managing Files
All file management activities can be found in the File menu:
Create a new file: File → New Window
Opening an existing file: File → Open
Running a file: Run → Run Module
Shortcuts for creating, opening and running a file are ⌘-n, ⌘-o, and the F5 key respectively.
DEMO - new window, open and run module
(Again, Feel Free to Follow Along!)
A First Program
"Hello world!" is traditionally the first program you write when learning a new language. It simply outputs "Hello world" (yeah, that's all). Follow these steps:
create a new file
type in …
run your program
you may be prompted you to save your file
if you haven't saved it yet, you'll be prompted for a file name
Modifying Your Program
Let's modify the program that we just wrote:
if your file is closed, reopen it
add a second line:
run your program
Making Mistakes
Let's purposely make a mistake, then fix it
if your file is closed, reopen it
add a third line, but leave off the last parentheses:
run your program
you should see a pop-up and a red highlight where your syntax error occurred
this occurs if your program is not syntactically correct
fix the mistake (how?)
DEMO - make a syntactic mistake, show where the error is
QUESTION - How do we fix this?
Making More Mistakes
Let's make a run-time error:
if your file is closed, reopen it
add a fourth line:
run your program
you should see the error in the console
let's read it and try to interpret it
fix the error
note that the current line number is on the lower-right-hand corner of the window (prefixed with "Ln: ")
DEMO - make a run-time error
QUESTION - what line number did the error happen on?
DEMO - find the line
Errors
Notice that we looked at two different types of errors:
syntax error - an error with the syntax/structure of the program; the program cannot run at all
runtime error - the program is syntactically correct, but some sort of error occurs while the program is running
A Quick Note on Syntax Highlighting
The different colors represent different syntactic elements
Some examples include
strings - green
built-in functions - purple
keywords - orange
strings - a primitive type of data in Python; a sequence of characters
keywords - (reserved words) words that have special meaning in Python
DEMO - function and for loop for syntax highlighting
The Output Window and Interactive Shell
The Interactive Shell
the output window can also be used to run Python code interactively
you can also go to Run → Python Shell to open an interactive session if it's closed
you can enter commands and have them return immediate feedback
the prompt, ">>>", means the interactive shell is waiting for input
try re-typing our hello world in the interactive shell, one line at a time
DEMO - hello world in interactive shell
Help!
Note that typing help in the interactive shell actually gives you help! Let's try it! →
You can use help on specific things… for example: →
Additionally, you can check out the Python docs by going to Help → Python Docs in the menu. →