Run your 1st python code

Run your 1st python code

In Programming world printing a Hello World! message to the screen will be the first program in a new programming language.
We can Run python program,

  1. In Interpreter prompt
  2. In Script file

1. Interpreter Prompt

Python comes with an interpreter that run in Command Prompt window or terminal, in this window we can try bits of python program without saving the entire program. To run python interpreter mode, Run command prompt and type “python” for Windows and “python3” for Mac or Linux if “python” doesn’t work then execute the code hit enter.

In Python we can write the Hello World! program in one line, the example is given below.

Example:

print("Hello this is Regu Ram")

Output:

Hello this is Regu Ram

To close interpreter prompt type exit() command and hit enter.

Python on cross-platform – Python is a cross-platform language, hence it runs on all the major Operating System.

2. Script File

In this type we can save our entire python code in a text file with the extension as .py (Eg: hello.py).
To run python script file, first navigate the prompt to the folder where you have saved the python script, to do that use cd command, the cd command is change directory, is used to navigate through your file in command prompt. file and simply type python and name of the script file with .py as extension in command prompt.

Example

C:\Users\regur>python test.py

test.py file

print("Hello this is Regu Ram")

Output:

Hello this is Regu Ram

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *