- As Consider we have already completed python setup in windows machine in the previous tutorial Now the main basic task is to write a full python code and execute our python first program.
you can write your small code on idle terminal and press enter to execute
Example:
print("I am from terminal ")
Output:
I am from terminal
you can use python idle terminal as a calculator Example:
>5+6-7
and press enter to execute you will get the final result in the next line
>4
- After the opening of the idle terminal just press Ctrl+n to open a notepad like a python text editor.
- And write the required code inside the editor.
- Now save that file as your required name with extension.py
Example:
filename.py
There are 2 way to run python file
1.Normal
- Open Python file in python IDLE.
- Now just press f5 or go running menu option and select run to execute the python file.
- Now the result will be displayed on your python Shell.
- Using Terminal
- Open command prompt or terminal in your shell.
- Go to directory copy path and in command prompt and change command prompt directory using the following command.
>cd "directory path"
- after changing directory just type
dir>python filename.py
- Now your required result will be displayed on command prompt
- if "python command is not recognized" occured
- Visit following path
My Computer >(Right Click)
Properties >
Advanced System Settings >
Environment Variables
- Just add the path as C:\Python37 (or wherever you installed python) to PATH Variable.
- And Also Add python/scripts path to an environment variable.