Differences Between the Shell and a File


Demo of the Shell

How do I get to the shell?

We'll use a program called IDLE. It comes with Python.
To run IDLE, open the command line and type IDLE.
For Windows, hit the Windows key, type "cmd", and hit enter.
For Mac, open the Terminal application in your Applications Folder.


What do I do with the shell?

The shell interacts directly with Python. You type one instruction, Python executes that one instruction. Things go back and forth, one at a time. You, Python. You, Python.
Try typing a math expression.

Python shell with math expression 4 + 10

You should see Python execute the math expression and print out the result.

Now try out the "print" statement.

Python shell with print 'Hello World' statement

Python will echo back whatever you asked it to print.

What if we remove the word "print" from our instruction?

Python shell with only "Wendy", without print statement

Python will echo back whatever you typed. But notice the difference between this response and our previous instruction with the word "print".

Now make your first variable.

Python shell with "x =

We've assigned x to hold the value of "Wendy".

And let's print out x.

Python shell with "print x" instruction

Demo of a File

In IDLE's menu, go to "File" -> "New File".
Now you should just see a blank file, without the triple carrot ">>>" that showed up on the next line of the shell.

What do I do with the file?
Cut and paste this code sample in the file and save it. I used the name "firstFile.py". Make sure to get the ".py" extension. Save the file. At home you could save to the desktop while testing. Now, in the IDLE menu, click "Run" -> "Run Module".


So only the lines with the word "print" actually printed out to the shell. The line with just the word "Wendy" did not print. This is a key difference, that was not nearly as obvious when our code was in the shell. We won't dwell on it for now-- it's enough to know that you need to include the word "print" each time we want output from running a file.

Key Differences

So now you've run some Python code in the shell and in a file. The key differences: