Getting Started with Python Hello World Program

This is the first step in learning any programming language. Let’s write our first Python program to print “Hello World” on the console.


Python Hello World Program

Here is the python script to print “Hello World” on the console.

print("Hello World")

Yes, that’s it. It could not have been more simpler than this.

Here is the output when this script is executed from the PyCharm IDE.

Python Hello World Program Output
Python Hello World Program Output

It’s the most simple program we will ever write. Let’s execute it from python command line interpreter too.

$ cat hello_world.py 
print("Hello World")
$ python3.7 hello_world.py 
Hello World
$
Python Hello World Program Execute From Terminal
Python Hello World Program Execute From Terminal

Printing “Hello World” from Python Command Line Interpreter

Python comes with interpreter, which is a shell like interface to run python scripts. Let’s see how to print “Hello World” message to console from python interpreter.

$ python3.7
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello World")
Hello World
>>> 
Python Interpreter Hello World Example
Python Interpreter Hello World Example

Understanding Python Hello World Program

  • The print() function is one of the built-in function. This function prints the argument to the console.
  • We are calling print() function with string argument “Hello World” so that it would get printed on console.
  • When we are executing python script file, statements get executed one by one. The print() statement gets executed printing the “Hello World” message on to the console.

Summary

We started our journey to learn Python programming with conventional “Hello World” program. We learned that the program can be executed from the PyCharm IDE and terminal. We also got some idea about python interpreter tool, which is very useful in running small python code snippets.