Welcome to Keren Automation, In this tutorial, we will learn about Different ways to Run Python Code.
Let’s continue…
Way1: Running Python using python.exe shell
If you cannot find the Python folder in your program files, go to System Properties window and copy the path to see the Python installation place.
Step1: Go to Python installation place and double click on python shell.
Step2: You will see the below screen; here you can start writing Python programs.
You can start writing Python code after “>>>” characters.
The problem with the above method is, as soon as you close the shell, your code will be gone.
To exit from interactive mode, you can use below commands
>>>quit( )
>>>exit( )
Way2: Running Python using IDLE:
Step1: Go to Programs and search for “IDLE” & Click on the IDLE to open.
Step2: You can start writing your Python code in IDLE editor.
Note: the above code is not going to be available after closing IDLE, so you can write code in editor and then save it to run.
Go to “File” => click on “New File”. Or you can use “CTRL+N” shortcut in Windows.
Note: Save Python files with .py extension.
Step3: To run the saved Python file, go to “Run” => Click on “Run Module” or press “F5”.
Now, we will see the execution of the above program.
Way3: Running Python code using Windows Command Prompt:
If you want to run Python using windows cmd, you can do it.
Step1: Open Windows CMD
Step2: Type “python” and hit enter.
Step3: Start Python code after “>>>” characters
Note: The above code is going to be vanish after you close the command promt.
Way4: Executing Python code in Command Prompt using Notepad++ Editor
Step1: Open Notepad++ editor and write python code.
Step2: Open Command Prompt and change directory to the drive, where your code files are existing.
Then you can run the code by the following command
>>python filename.py
Way5: Executing Python code using Online Compilers
If you want to execute Python code online, there are, multiple sites offering this service, some of them are listed below.
- https://www.onlinegdb.com/online_python_compiler
- https://www.tutorialspoint.com/execute_python_online.php
- https://paiza.io/en/projects/new?language=python3
Or you can search on google to find more sites.
Way6: Executing Python code in PyCharm IDE
Step1: Open PyCharm IDE
Step2: Create new Python file by right click => new
Write a simple addition program
To run the above program, go running => Click on Run
You will see the output like this
Way7: Executing Python Programs in Eclipse IDE:
If you want to execute your Python code in Eclipse IDE, follow the below process.
Step1: Launch Eclipse
Step2: Go to Help => Eclipse Market Place and Search for “PyDev” to install
Click on “Confirm”.
Note: Once the plugin installs successfully, Eclipse is going to Restart.
Step6: Go to File => New => Project and Select “PyDev” Project
Step7: Right-click on the project and select “New” File
Step8: Name the file and save it with .py extension
Step9: Start writing your code.
Step10: To run, go to “Run” and click on “Run”
You will see the output in the console
Happy Learning 🙂