In this tutorial, we will learn how to execute your first python program on python idle and other OS ; the same steps can be followed using Windows, Linux, and Mac OS.
Let us execute our first python program using python idle.
Step 1: Open idle.
Step 2: Click on File on the top menu and click on New File, or we can just use Keyboard shortcut “Clt + N”
How to code in python?
As you see, we have opened the new file on idle now, we will write the python code below and save it by any name using the Clt + S keyboard shortcut, but it should end with the “.py” extension.
Step 3: Let’s begin to code with python by typing the below code.
How to run a python program?
Let’s execute our first program by opening the Run menu from the top bar and click on “Run Module” or just the F5 key.
As you see, we have executed our first python program successfully.
How to run a python program in windows?
You can use the Windows default command prompt to run the python program in windows. To open CMD(Command prompt), you can type CMD on Run or search CMD in windows start.
Once you open the CMD, you can see a screen like below.
You can type python command to check whether Python is installed or not, and if it is not installed, you can check our Install python page to install python on your respected operating system.
When you type python and press enter, you see the python interpreter, as shown below.
You can type the below code to execute the python program.
All python programs are stored in a ‘.py’ file, so when we develop any python program, it will be saved in ‘.py’ format.
To run a python program, you can use the python command followed by the file name with the python extension.
The output will be as below.
How to run a python program on Linux?
We can use the Linux terminal to run python programs in Linux/Ubuntu, which can be opened by pressing ‘Ctrl + Alt + T’ or just search terminal in the search bar of your operating system.
Like Windows, we can type python commands in the Linux terminal to check whether Python is installed or not; if python is installed on your PC, you will see the image below.
To run a python program on Linux, you can simply use the python command followed by the program name, as shown below.