Milandeep Bassi

Creating and Running your First Program in Python

13th, January, 2020


Getting started with Python and IDLE

To start you need to download Python and IDLE (Integrated Development Language Environment).

IDLE is the development environment for the python language. Python scripts are created in a IDLE text editor before being executed in a Python interpreter. 

Python & IDLE : https://www.python.org/downloads/


Understanding the Python programming language

Python is a high-level language similar to C++, Visual Basic and Java. Python is considered an interpreted language because Python programs are executed by an interpreter. Command-line mode and script mode are how the interpreter is used. 

In command-line mode, you type Python programs and interpreter prints the results immediately:

>>> print (1 + 1)
2

The first line starts with >>> as this is a prompt for the interpreter to indicate it is ready. Alternatively you can write a program in a file, using the interpreter to execute the contents. This file is called a script.


Executing our first line of code

First you need to open "IDLE (Python 3.6)" to do this just use the Start menu to find the program.

The next thing you'll notice is that a new window has appeared. This window is the main window in IDLE. This is the interpreter. It allows entering commands directly into python and will then execute it, displaying the results back instantly.

Into the Python Interpreter we first need to check something off. Enter the line:

print ("Hello World!")

Once we hit enter the interpreter should return the word "Hello World!"

Python Shell

Writing our First Script

Now we're going to create a script. This is a document that can be opened and executes it contents any time. We use these as any code entered directly into the interpreter is lost when the application is closed.

First you need to start by opening a new file, from the file menu in the interpreter window. 

Into the window that opened type the following and save the file into a desired location.

print ("Hello World")

We can then run this new script we have created by either pressing F5 or going to the Run menu and running the program. This will then output the script contents into the Python interpreter.

Congratulations, you have successfully created your first program that prints "Hello World"