After you install Python on Windows, it’s time to run scripts you write.
Run script on Windows
There are a few methods to run Python scripts on Windows:
- Command Line
- IDLE (Integrated Development and Learning Environment)
After you create your file, let’s say main.py, navigate to search icon or search box on the taskbar, type cmd, and choose Command Prompt.
After you open the command line, navigate to the file location and type:
This command will execute the main.py script.
If you want to stop the script before its execution, press Ctrl + C, or Ctrl + Pause / Break.
IDLE (Integrated Development and Learning Environment)
The next tool is IDLE. It has been included in Python since 1.5.2b1, and it’s created to be a simple IDE for beginners, mainly for educational purposes.
To open it, type IDLE in the search bar and choose the icon.
Inside the window, you can write Python code.
For editing multiline code, this interface is not very good. The main purpose of the IDLE is to show the output from running scripts.
What we need to run the script is to go to File >> New File. Enter the following code.
def foo(x): return x*x def main(): print('Hello!') print(foo(3)) if name == 'main': main()
Save the file with the .py extension and hit F5 to run the code.
This is the result we are going to get.
You can write the Python code in the most straightforward available text editor, such as Notepad, or a little bit complicated free editor called Notepad++.
But you are missing a lot of features that can make your job easier.
Instead, you should use free or commercial IDE. This is the best method to edit and run Python scripts.
Python is a very popular language, so there are a lot of applications to help you work with the code. On Wiki, you can find the whole list of IDEs.
I use PyCharm from JetBrains. You can download it for free from their website. The free Community Edition is quite powerful and sufficient for many users, especially beginners.