Python hello world program

Python is a scripting language that runs using a python interpreter. The interpreter converts the program (python text file with “.py” extension) into hardware understandable format.

Let us see a simple hello world program using python language.

# helloworld.py
# Below code prints 'Hello World!' string.

print('Hello World!')

While we install the python program, it gives a set of executables in which one executable is “python” which generates an interpreter and makes it run on hardware. Below is how we use that executable.

$python
Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello World!')
Hello World!

Here in the above program, we are using a function called ‘print‘ and a string ‘Hello World!’.

‘print’ is an inbuilt function that prints the string argument. A string is a sequence of characters that are in between single quotes (”), double quotes(“”) or triple quotes(”””).

# Below code prints 'Hello World!' string as well.
# String with triple quotes.
strng = '''Hello World!'''
print(strng)

A simple python program (Hello world example)

# helloworld.py
# function to print 'Hello World!'.
def greet(text):
    print(text)

# calling function that prints given text
greet("Hello World!")

We save the above code into a file named ‘helloworld.py’ (with .py extension) and run the code using the python executable as shown below.

# Output
$python helloworld.py
Hello World!

Hope this python hello world program helps you to start learning python. Happy Learning!.