Advertisement



< Prev
Next >



The First Python Program in IDLE




In our last tutorial, we have discussed steps to install the latest release of Python. Installing Python(as explained in our last tutorial) also installs its IDLE IDE i.e. an interactive integrated development environment used to code in Python, which highlights all the keywords and has a Python Shell, also known as interpreter, responsible for the execution of the Python programs, display their output and to notify us about the errors in a program.

In order to execute your first python program using IDLE IDE, we need to go to the folder where the IDLE IDE has been installed and execute it.




Executing the IDLE Integrated Development Environment


In our last tutorial of discussing steps to install Python, we did not play with the default installation settings, hence, the Python on our system has been installed in its default location i.e.

C:\Users\Your_UserName\AppData\Local\Programs\Python\Python37\Lib\idlelib


Double-clicking the file idle.bat in this folder, executes the IDLE IDE and opens the window of Python Shell, with a prompt >>>(at which you could type in a code to execute).

Figure 1






Using the Python Shell window, we could create a new separate file by clicking on the File-> New File menu options on the top menu and code in it. Let us name this file first.py.

Note: All console programs in Python are stored with a .py extension, whereas all GUI Python programs are stored with .pyw extension.


By default, the programs coded in a separate file using IDLE will be stored in the same directory where the IDLE is stored, i.e.

C:\Users\Your_UserName\AppData\Local\Programs\Python\Python37\Lib\idlelib

but you could store your Program in a directory of your choice and that's what we are going to do now. We will save the file of our first Python program in a location D:/Python( as shown in the picture below), and we are going to name it first.py.


first.py
Figure 3






To execute this code in a separate file, we have three options -

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON


Advertisement