how to create python script using IDLE by manish sharma

Python Scripts Using IDLE

A programming script is a file which contains a set of instructions and has a unique name as well as a dedicated file extension which is accepted by the language. As programming scripts are saved as a file onto the file system of an operating system thus we can reuse them whenever we want. That makes life a lot easier. In this tutorial you will learn how to properly create a Python Script and Execute them using IDLE graphic user interface.

Before we jump on to the tutorial let’s first see what is this IDLE graphic user Interface.

What is IDLE?

IDLE stands for Integrated Development and Learning Environment. It is an Integrated Development Environment (IDE) with minimalistic features. This IDE comes as a part of the whole package of Python software. It means if you have installed the Python as demonstrated in tutorial 1 then IDLE is already installed on your system.

 As said above, it’s a minimalist software which means, using it you can only write, edit and execute a Python Program. No other advance features for example debugging is available. Because of this reason IDLE is not very famous among the community. But this software is sufficient for me to teach you how to create and execute a Python Script in Windows 10.

Is it necessary to use IDLE for Python Script?

No, it is not necessary to use IDLE for creating a Python Script. You can use whatever software you want. Even in future tutorials we will be configuring some high end software for Python Programming.

What file extension should we use for Python Script?

Every programming language has a finite set of file extensions. These file extensions help the compiler or the interpreter of that language in recognizing the files. With Python Programming Language we use *.py file extension for creating a Python Script.

In general there are total 19 python supported file extensions. You can read about each of them in detail here.

Then what is the use of *.pyc file extension?

Similar to programming language like Java, python’s interpreter compiles the source code of your scripts into a special machine code called bytecode. Bytecode is then executed by Python’s virtual machine. Since Python is an interpreted programming language, therefore whenever we interpret python scripts using the Python’s interpreter, it automatically generates a file with *.pyc extension corresponding to the scripts.

What is the file name format for Python Script?

Like other programming languages you can name your script whatever you want. Just make sure to specify the *.py file extension at the end of the name.

File_name.py

How to create Python Script?

There are two ways of creating a Python script.

  1. Create a text file and rename it with *.py extension
  2. Create the script and save it using an editor or IDE.

As, I have already demonstrated the first method (Create a text file and rename it with *.py extension) of creating a Python script in the video tutorial which you can check here so now we will learn the second method of creating the script.

Although you can use any software you want to perform this task but for this tutorial our editor of choice is IDLE.

Step 1: Open up IDLE

You can open up the IDLE editor from your start menu. Just go to the start menu à Python 3.7 à IDLE or simply search IDLE in your Cortana or start menu.

Step 2: Create and save your script.

Clicking on IDLE will open up the Python shell. You can either start writing your code here or hit control + N and open up a new file. Write your code in this file and save it. IDLE automatically saves all the files either with .py or .pyw file extensions which means you don’t need to write the file extension explicitly.

*.pyw file extension

Those Python scripts that are created for Windows environment & are executed by python.exe have the extension *.pyw.

In this tutorial we learnt what are scripts and what the available file extensions in Python Programming language are. In addition to that, what is IDLE editor and how to write Python script using IDLE. Hope you enjoyed it. Stay tuned as in the next tutorial we will be learning how to execute scripts using command prompt.

Thanks and have a great day!