Python Environment

Python is an interpreted language. You will install the PYTHON language on your computer along with its Integrated Development and Learning Environment (IDLE). We will be using IDLE as the primary environment throughout this course. To install Python, visit the official Python website.

There are two ways to write Python code:

  1. You can write your Python program one line at a time at the >>> prompt in the Python shell. This is called the "interactive" mode.
  2. Another mode for your programs is the "script" mode. You use an editor to write all of your Python code at one time, and then you save them as a file with the .py file extension.

Which Mode Do I Use?

In this course, we will be writing code both in the "interactive" mode and the "script" mode depending on the scenario. We will start off with this method to learn some basic concepts about the Python language. However, for the most part of the course, we will be writing code using "script" mode since it's better fitted for more complex tasks.

We will be going through a lot of sample code or exercises in this course. You are expected to run all of the sample code in the course.

Interactive Mode

To help facilitate with your learning, you will see notifications such as below indicating that the code are written in the "interactive" mode.

info

Note the >>> prompt in the examples below indicates that they are running in the PYTHON shell using the "interactive" mode.

The sample code are presented in the green callout box such as below. The >>> prompt signifies that the code is entered in the Python shell in the "interactive" mode. After the statement, you will hit the ENTER key on your keyboard and the statement will be executed. In the example below, the second line without the >>> is the result after the statement is being executed.

>>> print ('My first Python program.')
My first Python program.

Script Mode

A notification such as below indicates that the sample code should be written in the "script" mode, and saved as a file with .py extension.

Example: first_python.py

info

The examples below are written in "script" mode.

print ('My first Python program.')

To "run" the program, you can either:

1. use the Run menu in the IDLE environment, or

2. use the command: python filename.py in the Command(PC) window or python3 filename.py in the Terminal(Mac) window.