Getting started with Python (part 4)

In this tutorial, I’ll explore the Python interactive shell, IDLE, and how to use the interactive shell from PyScripter.

The interactive Python shell is basically the Python interpreter, running on code that you enter directly into it, as opposed to when you run a script and the input comes from a script file.

The shell is very useful for testing theories without the hassle of creating a script file, modifying it, running it, editing again, running it again, etc.

You can bring up the shell in a command prompt, but I prefer to use IDLE, which is the IDE that comes with Python. I think PyScripter is better, in terms of project management, debugging, and editing.

As an interactive shell, IDLE is pretty good.

When IDLE is loaded, you’ll be presented with the following prompt:
pyshell_start

The >>> prompt means that the shell is ready to accept Python code.

We can type equations in if we wanted, or, we could define a function:
pyshell_func

When you’re inside of a code block like a function, you may see no “prompt” character, as shown above. If you are using the command line shell, or the shell in PyScripter, you might see “…”.

When you’re done coding in the function, just hit enter twice. If you don’t indent each line (this happens automatically for some lines), the shell will assume you’re done defining the function.

Let’s try calling the function:
pyshell_callfunc

You can access an interactive Python shell from inside of PyScripter too. Let’s take a look:
pyscripter_shell

Notice how instead of just plain white space, “…” is used while inside of a code block.

Just like the PyScripter editor provides code completion and call-tips (Ctrl + Space), both IDLE and the Python shell in PyScripter offer similar functionality.

Newbs might be interested in part 5 of this series, in which I’ll explain what object oriented programming is, and how it’s applied in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>