How do I run a Python file for the first time?
You'll be able to: Execute a Python script
- Risk
- Safe to try
- Windows
- Windows 11 · Windows 10
Filed under Programming & tools
The steps
- 1
Open Visual Studio Code (or your installed editor) and create a new file by clicking File > New File.... An empty editor tab appears.
- 2
Save the file by pressing CtrlS, name it
main.py, and click Save. The tab icon turns into the blue and yellow Python snake logo.Why name the file with .py?
The
.pyfile extension tells both your editor and your operating system that this is a Python program so they provide proper syntax coloring and execution. - 3
Type
print("Hello, World!")inside the editor and press CtrlS to save. The white dot on the tab disappears, indicating changes are saved. - 4
Click the small triangle Play icon in the top-right corner of the editor window, or press Ctrl~ and type
python main.py. The integrated terminal opens at the bottom, runs your file, and printsHello, World!.
It looks different on my screen
If the terminal says 'python' is not recognized, make sure you have installed Python with PATH enabled, or restart VS Code so it picks up your settings.
Did this work?
Updated 2026-08-24اقرأ بالعربية