Hello Word with Python

First Steps

We will now see how to run a traditional 'Hello World' program in Python. This will teach you how to write, save and run Python programs.There are two ways of using Python to run your program - using the interactive interpreter prompt or using a source file. We will now see how to use both of these methods.

Using The Interpreter Prompt

Open the terminal in your operating system and then open the Python prompt by typing python3 and pressing [enter] key.Once you have started Python, you should see >>> where you can start typing stuff. This is called the Python interpreter prompt.At the Python interpreter prompt, type:

print("Hello World")

followed by the    [enter]    key. You should see the words    Hello World    printed to the screen.Here is an example of what you should be seeing, when using a UBUNTU 16 OS as a computer. The details about the Python software will differ based on your computer, but the part from the prompt (i.e. from >>> onwards) should be the same regardless of the operating system.

ubuntu2@sanjeev-ubuntu2:~$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World ")
Hello World

Notice that Python gives you the output of the line immediately! What you just entered is a single Python statement. We use print to print any value that you supply to it. Here, we are supplying the text Hello World and this is promptly printed to the screen.

How to Quit the Interpreter Prompt

If you are using a GNU/Linux shell, you can exit the interpreter prompt by pressing [ctrl + d] or entering exit() (note: remember to include the parentheses, ()) followed by the [enter] key.If you are using the Windows command prompt, press [ctrl + z] followed by the [enter] key.

Using A Source File

Start your choice of editor, enter the following program and save it as    hello.py .

print("hello world")

Where should you save the file? To any folder for which you know the location of the folder. If you don't understand what that means, create a new folder and use that location to save and run all your Python programs:

IMPORTANT: Always ensure that you give it the file extension of    .py , for example,

To run your Python program:

1. Open a terminal window

2. Change directory to where you saved the file, for example,  cd /tmp/py

3. Run the program by entering the command python hello.py .The output is as shown below.

     python hello.py

     hello world


Write a program that greets the person by printing the word "Hi" and the name of the person.