In the previous postings, we learn python is an interpreter language that means it executes line by line of code. Python comes with interactive shell known as python shell which is used to execute python coding lines or commands and the results view instantly after execution of the command.
See the below in the python shell.
>>> print ("hello")
hello
>>> print 2+3
5
>>> print 2/5
0
>>>
Type a code or instruction and then press enter it gives results instantly like above.
To use python shell in your PC, type python in run and find Python Command line and click on that, the above screen is opened that is python shell.
Till now we learn the single command execution, in the case multiple line of code or python file execution follow the below steps.
Unlike Java and c python programs also execute from cmd.
Step1:
Create python program in note pad or python environment and save that file extension with .py. (remember that file location).
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = float(num1) + float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
I saved the above file with name sum.py in Documents folder.
Step2:
Open Command prompt and change directory to Documents.
See the below snap I was navigating to Documents folder.
Step3:
Execute out program by typing Python Sum.py
Python programname.py (press enter) the program will execute. See below picture.