Python Interactive Example

When the Python interpreter is run interactively it:

  1. Outputs a prompt, usually >>>
  2. Waits for the user/programmer to enter a statement followed by a return
  3. Processes and executes the statement
  4. Goes back to step 1.

Example of an Interactive Session

When Python is run interactively typing a variable name will cause the variable's value to be output.

Type the following into the Python interpreter, except for comments.

2 + 3 * 4
a = 2
print(a) # a's value is output
a # a's value is output, works only when iteractive
b = 3
c = 4.1
a = a + b * c  # a gets a new value
a = "Hello World!" # a is a string
a = 8 / 3
a = 8.0 / 3.0

Python Programs

Although a program could be typed in the interactive session it is not very convenient and would be lost when the session is terminated.

Usually programs are typed in using a tool called an editor.

The file created by the editor is then run.

An editor familiar to many is Microsoft Nodepad.

An editor only allows unformatted text to be typed in (and saved).

An editor is supplied with the usual Python installation.