To create and run a Python script in Windows, follow these steps:
Open a text editor, such as Notepad, Sublime Text, or Visual Studio Code.
Write your Python code in the text editor and save the file with a .py extension. For example, you could save a file called my_script.py with the following contents:
Open the command prompt by pressing Win+R and typing cmd followed by Enter.
Navigate to the directory where you saved your Python script using the cd command. For example, if you saved the file in the Documents folder, you would type:
Run the script by typing python followed by the filename. For example:
Press Enter to execute the script. You should see the output Hello, world! printed to the command prompt.
Note that you must have Python installed on your system in order to run Python scripts. If Python is not installed, you can download it from the official Python website: https://www.python.org/downloads/windows/. During installation, be sure to select the option to add Python to your system's PATH environment variable so that you can run Python scripts from the command prompt.
or View our previous post , Click here how to install Python in win 11 or Ubuntu
Comments
Post a Comment